+ 1
Explain for loop in detail
2 Antworten
+ 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;
}
+ 1
loops are the conditional codes which keep on running when condition is true..
they stop when condition become false