while (condition) {
// code block to be executed
}
The while loop loops through a block of code as long as a specified condition is true:
In the example below, the code in the loop will run, over and over again, as long as a variable (i) is less than 6:.
The example below uses a do/while loop. The loop will always be executed at least once, even if the condition is false, because the code block is executed before the condition is tested:.
Example:In the example below, the code in the loop will run, over and over again, as long as a variable (i) is less than 6:
i=1 while i < 6: print(i) i +=1