Repetition statements is one types of control statements.
The repetition consists of while loops, do-while loops and for loops. Each loop must have initial value, control expression and next value.
The three forms of loop statements are expressively equivalent. We can write a loop in any of these three forms.
While loops - Do the loop body if the condition is true. Loop body is executed, until the condition becomes false.
Do-while loops - The body of the loop will execute first before checking the condition.
For loops - Same as while loops, just the difference is the initial action, loop continuation condition and action after each iteration is written in the bracket form.
Moreover, automatic counter loop is a loop which use variable as a counter that starts counting at a specified number and increment the variable each time the loop is processed. (The beginning value, ending value and increment value may be constant.)
In addition, nested loop is a loop within a loop, an inner loop within the body of an outer one. How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again. This repeats until the outer loop finishes.
Other than that, "Break" and "Continue" can be used to alter the normal flow of a loop.
Break - Allows to exit a loop without checking the loop condition.
Continue - Causes the execution control to be transferred to the loop condition, without executing the rest of the loop body.
That's all for the summary of loops. Hope you find it helpful for those reading. Thank you. See you again next week. Bye..
LIM XUE TING
183615
SSK3100
(Group15)
Next blog: hennyabigail.blogspot.com (Henny
Abigailwillyen Sinjus)
No comments:
Post a Comment