While & Do/While Loops
Last updated
Last updated
Probably the simplest loop structure, this code block will run if and only if the condition is true. Once it becomes false, the loop stops. You can also break out of the loop with a break;
statement.
Keep in mind that the while loop may not run at all, depending on the condition.
The syntax of a While loop is some of the simplest possible:
The Do While is a variation on the While. It is guaranteed to run at least once but it will only loop back to the top if the condition is true.
The syntax is similar to the While loop but notice the differences - especially the semicolon ending the statement.