Thursday, January 14, 2016

Difference between For Loop and While Loop

For Loop:
- fixed repetition loop

- run given number of times regardless of how the loop changes the values of the variables

- counter value increases/decreases depending on loop min, max, other requirements; no separate statement in loop body

- use separate variable to run loop, can also start decreasing


While Loop:
- can have various conditions joined with AND/OR

- enters loop body only when condition is met

       - if condition not met, moves on to statement after the end of the loop

- statements within while loop change criteria