More For Loop
One common question we often encounter is to write a for loop for a given output.
We will follow a 5-step process to come out with a For loop.
Step 1: write a program without using while/for loop
Step 2: Identify the constant part and the variable part
variable - the number "1 ... 6"
constant - the rest of the code
Step 3: Use a variable to replace the variable part
Step 4: Identify the starting number, the ending number and the step/update
- start: 1
- end: 6
- step/update: +1 (add 1 every time)
Step 5: Construct a for loop
Let's recap the 5-step process again: