What is the difference of the structure "while" and repeat in VisualG?
What is the difference of the structure "while" and repeat in VisualG? Do you have an example?
1 answers
The main thing is that the condition of enquanto
is evaluated right on its input, so it can not even execute anything of the loop if the condition is already false, while (excuse the pun :) ), that the condition of repita
is only evaluated for the first time at the end of the first execution of the block.
Is also different because enquanto
contained while (no pun intended) the condition is true, and in repita
it repeats until it reaches that condition, so it repeats as long as the condition is false.
var i: inteiro
inicio
i <- 0
enquanto i < 10 faca
escreva(i)
i <- i + 1
fimenquanto
var i: inteiro
inicio
i <- 0
repita
escreva(i)
i <- i + 1
ate i >= 10
I put on GitHub for future reference .
See what is the utility and importance of " do... while"?. do-while
is a mixture of the two. It always lets run once, ma the output condition is false, equal is in while
. In practice few languages, none strongly mainstream uses a construction equivalent to repita
.