The For Loop
Learn about the usage of 'for' loop along with some optimization techniques regarding loops.
We'll cover the following...
Introduction
You will now learn another loop that is perfect for iteration: the for loop. This loop combines several lines of code into one. The execution of the ‘for’ loop is identical to the ‘while’ loop:
Press + to interact
initialization_of_loop_variable;while ( condition ) {statements;increment_loop_variable;}for ( initialization_of_loop_variable; condition; increment_loop_variable ) {statements;}
The ‘for’ loop has everything you need in one line. You don’t have to mix your loop body with the increment of the loop variable. The execution of the ‘for’ loop is as follows:
initialization_of_loop_variable
- check
condition
. Ifcondition