Greets, my friends.

Now we are going to see how while works, and how to use it.

“While” is used for loops, like “for” and “do while”, but every functions has its differences.

The structure of while is:

while (condition)
{
Conditional code: Here is where you put the increment, decrement or any statements to do every loop;
}

While is used when the conditional code is more complicated than just an increment or decrement, but it works the same way as “for”, it repeats the statements until the condition is true.

This is example do the same as the one I used for “for”, it prints the numbers from zero to ten, but using while:

while

Easier than for, I think. And this should be enough to you to understand how “while” works and how to use it.

Any questions must be done, and I will ask every single one. Have an awesome week.

The code of the example: https://github.com/hrglez/TC1017/blob/master/while

CC BY 4.0 Loops with while! by hrglez is licensed under a Creative Commons Attribution 4.0 International License.