For Loop

For Loop is a bit more complex command.
You give it a variable name, its initial value, its end value, and a step (increment).
It is the same as if you:

  • Declared an Integer i with an initial value
  • Added While with condition i <= end
  • Assigned i = i + step at the end of While

Let's write the same program as before, print first 5 numbers:

  • Declare a For Loop with variable name i
  • Set i start value to 1
  • Set i end value to 5
  • Set step to 1
  • Output i in For body

We achieved the same result, but with a lot less code.
Plus, it is more readable than before!


Wow, great job, this is the last Intermediate level tutorial.
Continue learning with Advanced level tutorials.

3 / 3