2
What is the difference of the structure "while" and repeat in Visualg? It can be exemplified?
2
What is the difference of the structure "while" and repeat in Visualg? It can be exemplified?
2
The main thing is that the condition of enquanto
is evaluated right on your entry, so can not even perform anything of the loop if the condition is already false, while (sorry the pun :) ), that the condition of the repita
is only evaluated for the first time at the end of the first implementation of the block.
It’s different too because enquanto
contained while (without pun) the condition is true, and in repita
he repeats until he reaches that condition, so he 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 in the Github for future reference.
Behold What is the usefulness and importance of "do... while"?. The do-while
is a mixture of the two. It always lets run once, but the output condition is the false, equal is in the while
. In practice few languages, none strongly mainstream uses a construction equivalent to repita
.
You can do the same "repeat" functions with the structure "while"?
You can always do the same thing, but it’s not always the most convenient way, so there are two ways.
@Arthur Take a look at [tour], in addition to accepting answers, you can vote on everything you find useful on the entire site.
Browser other questions tagged loop while visualg portugol do-while
You are not signed in. Login or sign up in order to post.
One will be executed while the condition is true. The other, will be repeated until the condition becomes true.
– Renan Gomes
Simple answer, but it removed the doubts that I had. Obgd
– Arthur