This document discusses different types of loops in computer programming including for loops, nested for loops, while loops, repeat loops, and the break and next keywords. For loops are entry-controlled and iterate over a known sequence. Nested for loops run multiple inner loops within an outer loop. While loops are also entry-controlled but are used when the number of iterations is unknown. The break keyword exits a loop entirely, while next skips the current iteration. Repeat loops run continuously until a break condition is encountered.
2. Loops
For loops
Nested for loops
While loops
break
Repeat loops
next
3. In computer programming, a loop is a sequence of instructions that are
continually repeated until a certain condition is reached.
Loops can either be entry-controlled or exit-controlled.
Entry-controlled loops run only if the condition for the looping process stays true.
Exit-controlled loops run at least once, regardless of the condition, conditions are
checked for only at the end of the loop block.
4.
5. For loops are an entry-controlled type of loops, i.e., conditions are given on the
entry of the loop.
If the conditions are not satisfied, then the loop doesn't execute.
Otherwise, the loop runs until the condition becomes false.
It is used to iterate over the items of a sequence, usually only when the range of
the sequence is known.
Update statements are not needed as the loop automatically updates the counter
variable.
6.
7. For loops can be nested, i.e., for loops can be placed inside of other for loops.
If for example, the outer loop will make 'm' iterations and the inner loop will make
'n' iterations, then the total number of iterations made will be m * n.
8.
9. While loops are another entry-controlled type of loop in R.
While loops are usually used when the total number of iterations are not known,
although they can also be used when the number of iterations are known.
Update statements have to be explicitly mentioned in while loops.
10.
11. The 'break' keyword is used to 'break' out of a loop abruptly in between its
execution.
Once a 'break' statement is encountered in a loop, the control exits out of the loop
completely.
12. It is a simple loop that will run the same statement or a group of statements
repeatedly until the stop condition has been encountered.
Repeat loop does not have any condition to terminate the loop, a programmer
must specifically place a condition within the loop’s body and use the declaration
of a break statement to terminate this loop.
If no condition is present in the body of the repeat loop then it will iterate
infinitely.
13.
14. The 'next' keyword is used to skip the current iteration in a loop.
Once the 'next' keyword is encountered in a loop, the control will instantly skip
that iteration.