Coggle requires JavaScript to display documents.
A "While" Loop is used to repeat a specific block of code an unknown number of times, until a condition is met.
For example, if we want to ask a user for a number between 1 and 10, we don't know how many times the user may enter a larger number, so we keep asking "while the number is not between 1 and 10".
If we (or the computer) knows exactly how many times to execute a section of code (such as shuffling a deck of cards) we use a for loop.
The while construct consist of a block of code and a condition.
The condition is evaluated,and if the condition is true,the code within the block is executed.
This repeats until the condition becomes false
Because while loops check the condition before the block is executed,the control structure is often also known as a pre-test loop.