While and do while

Published by Mario Oettler on


A while loop evaluates the condition at the beginning. As long as it yields true, the loop is repeated.

while (repeat == true) {
    // repeat as long as repeat is true.

do while

In a do while loop the statements are executed at least once. The condition is checked at the end.

 do {
   // execute at least once
   // repeat if the condition is true
} while (condition);