#mastery 22

 

In this mastery I am going to expalin when to use a type of repetition.

 

FOR:

We can use for as a loop when you know very well how many times the repetition will be done.

example:

for(i=1; i<=10; i++)      In this case I know that the loop is going to be repeated 10 times, so now I can use a FOR loop

 

DO WHILE:

We use a do while when you are not sure how many times the loop will be repeated, it is going to continue while the conditional is true, when it is not it will go out of the loop.

example:

do {

cout <<“Hello<< endl; 

} while (nu

1==1); 

as you could see we d

mo not know how many times it is going to be done 

 

WHILE DO:

It is exactly the same than the do while, but in this case the structure is the oposite and at the first time it is going to do the order if the condition is true.

example:

while (num1==1); do {

cout<<“Hello”<< endl;

}

 

 

CC BY 4.0 #mastery 22 by Osvaldo Mendoza is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.