Pages

Sunday, June 10, 2012

While loops


In this lesson we are going to learn about the while and do-while loop. Those loops have not a defined initial number of cicles to do. They will execute the code inside the loop until the condition is false. The difference betwenn the do-while loop and the while loop is that the first one will execute the code inside its loop almost one time, as the while loop will look first if its condition is right to execute its code.

Example:
int a = 5, b = 3;
//this loop will never be executed
while (a < 5){
a--;
}
//this will be execute until a is less or equal than 5
do{
a--;
}while(a > 5);

No comments:

Post a Comment