When we want to execute some code multiple times, we can always copy-paste those commands.
But that is not very efficient or readable, so we have commands like
While command has two parts:
condition- checked each time, before
Whilebody is executed
body- list of commands executed when
Let's write a program that prints numbers 1 to 5:
- declare an integer
xwith value 1
- add a While command with condition
x <= 5
xin While body
x = x + 1in While body
You should see numbers
1,2,3...5 printed in the output panel.
Notice the Assign command:
x = x + 1.
You can use
x's previous value (before Assign was executed), when calculating its new value! How cool is that? :)