Loops
Loops help perform repetitive activities many times. Loop will repeat so many times as condition for the loop is false.
Common loops are “for” loop, while loop and repeat until loop.
For loop specifies condition for the loop and alternatively a step for each iteration of loop cycle. By default this step is equal to one and it can be omitted.
There two more types of loops. These are repeat until loop and while loop. Repeat until loop will check the condition before the loop cycle and while loop will check the condition at the end of the loop cycle. It is important to modify variable that is used if that loop condition, otherwise it is possible to end up with indefinite loop.
Indefinite loop may also happen with a for loop. By default a variable that is used for loop condition will be changed. If that variable value is reverted back or changed inside of that loop than it is possible to have indefinite loop.
You are probably familiar with hour glass mouse cursor in Windows or beach ball in Mac OS, indefinite loop will do something similar to it. Something is done, but what is done is a mystery, and nobody knows when it will be over.
Comments
Post a Comment