+ 4
Pls explain me about loops!!!
3 Answers
+ 3
for (initialization; condition; change)
{
body
}
First the "initialization" is done.
Then the "condition" is checked.
If the condition is true, the "body" of the loop is executed. If not, control passes to the statement (if any) directly after the body of the loop.
After the body is executed, the "change" is done. This can be increment, decrement of the initialized variable(s) or something else.
Now the condition is checked again & the procedure repeats as before.
Observe that this is just like the while loop as shown below.
initialization;
while (condition)
{
body;
change;
}
+ 2
Loops repeat an action for example: ( I'll use a for loop):
for (amount of time that usually uses a variable) {
//do something
}
0
if we wants to do the same work repeatedly then loops are used