For Loops
for
loops are the most concise loop construct.
For for
loops, parenthesis are required, this is described in the Control Flow section.
There syntax is highly resemblant of their C counterpart:
The syntax of the for
loop is:
Essentially the way this works is:
The output of the first for
example would be:
This is because the variable i
is initialized to 0
at the beginning. Then, because i
is less then 5
, it will keep running the code block until i
is not less than 5
. This happens because the i++
increases i
everytime, after, the code block (i.e. the print
) is executed.
Last updated