Wednesday, January 28, 2015

For Loops

A for loop is a loop that you can get out of/it will eventually end. It consists of three parts, initializing, conditional test, and iteration. Initializing assigns the variable with a known value. The conditional test checks if the current value of the variable is either greater then, less then, or equal to a number, and iteration is something done each time when the loop is complete.

A example is:
For(int z = 5 ; z <= 7 ; z++)
{
// do something here
}

In the above example, the variable z is being assigned to the value of 5, and it will loop through 3 times, because z++ is adding 1 to the value of z each time, so after 3 loops. the value of z will be 8, which is greater then 7, so the conditional test will turn out false, stopping the loop.

Also, below is a picture of what I wrote in my notebook!




Over & Out!
Elise

No comments:

Post a Comment