Hello ! Today I thought I would talk about 2 other kinds of loops, the “while” and the “do…while” statements.Enjoy!
The while statement continually executes the same block of code as long as a condition is true.
You can implement an infinite loop by using the while statement as follows:
The difference between
while is that
do-while evaluates its expression at the bottom of the loop instead of the top. Therefore, the statements within the
do block are always executed at least once.
//your code here
Notice how there is a semicolon at the end of the do-while statement. This is the only statement that ends in a semicolon so be careful not to forget using it ,thou I am pretty sure that the compiler will keep that in mind for you.
I hope this helped your understanding of the “while” and “do-while” statements.
Keep on coding 😉 !