Explain the For Loop - Computer Programming?
Similar to the while statement, for loop is an entry controlled loop and the code of the for loop will be executed itereatively. The for loop facilitate well where the number of iterations of the loop is recognized before the loop is entered. The head of the loop consists of three parts separated by semicolons.
- The first is to run before the loop is entered. This is generally the initialisation of the loop variable.
- The second part is a test, the loop is exited when this returns false.
- The third part is a statement to be run every time the loop body is completed. This is generally an increment of the loop counter.