+ 1
Can anyone explain loops to me please?
logic for loops
3 Answers
+ 1
A loop is a block of code that continues to run while a certain condition is true.
while, do/while and for are all loops.
e.g.
int a = 1;
while (a < 6)
{
cout << a;
a++
//prints 12345
}
0
Loop are flow control blocks... they control the "flow" of the program, allowing to repeat a number of times a block of code. Everything that is inside the loop block will execute (or no) as far as the conditions set on the loop allow it (the parameter evaluate to true in while and do-while loops and the third parameter on the for loop).
Hope it helped.
0
thanks