FOR LOOP

For loop will repeat as many times as you specify:

for( int x = 0;  x < 5;  x++ )
{
print x
}

This loop will run until the condition x < 5 is satisfied and print numbers 0 to 4.

One thing that often causes trouble is endless loops. The following code:

for( int x = 0;  x == 5;  x=x+2 )
{
print x
}

will print 0, 2, 4, 6, 8… and it will never hit  x==5  condition that should cause it to stop.

Avoid creating endless loops, especially in critical apps where the computer is controlling machines or other external processes.

Leave a comment

Your email address will not be published. Required fields are marked *