Can somebody tell me how to use loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can somebody tell me how to use loop

loop

26th Jun 2016, 2:45 PM
rise of the titan
rise of the titan - avatar
2 Answers
+ 1
loop basically used to done those work which we have to done many time.
27th Jun 2016, 6:12 AM
DEATH WALKER
DEATH WALKER - avatar
0
There are three kinds of loops. for, do-while and while. for: for( inizialitation of variable; test to continue doing the loop; what to do in each step) { ... } an example: for ( int i = 0; i < 10; i++) { ... } this can be traduced to: First, create a variable i and assign 0 to it. Each step, if i < 10 is true continue doing the loop and increment i by 1. do while: do { statements } while (condition); The name says it. Do what is inside the curly braces while the condition is true. example: int i = 0; do { cout << i++; } while (i < 10); This prints the numbers 0 to 9. while: while ( condition ) { ... }; Exactly the same as do while, except for, if the condition is false in the loops first iteration, the code inside the while doesn't execute, while in the do-while, if the condition is false at first, the code inside executes once.
26th Jun 2016, 3:43 PM
Garme Kain
Garme Kain - avatar