There are very specific differences between the three types of iteration (or repetition) which are important to understand when selecting which one to use. The table below outlines these differences.
Repetition Type |
Counter increment |
Initialization |
Condition to loop |
For |
Automatic |
Automatic |
Continues until the counter reaches the value specified in the TO clause |
Repeat- Until |
Manual |
Manual |
Will only loop if the condition is false |
While |
Manual |
Manual |
Will only loop if the condition is true |
The for loop above is very simple and allows us to pick up the three main parts of repetition. These are-
for (<start value> ; <condition>; <increment>)
Below is the steps you must follow to perform the conversion -
Consider this for loop -
Step one - swap keywords
Step two - change the start value
Step three - increment
Step four - (not needed for java)
Note - In psudeocode we need to do some more work. The image below shows this