while loop

A loop that keeps repeating its block as long as a condition stays true, checking the condition before each pass.

In more detail

Use while when you cannot know in advance how many passes are needed, such as reading input until the user types nothing. Something in the body must eventually make the condition false, or the loop never stops. When the number of passes is known, a for loop is simpler.

Examples

while [[ $count -le 3 ]]; do ((count++)); done
temperature = 115
while temperature > 112:
    temperature = temperature - 1

Related terms

Taught in

References

Certification courses