Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Show the numbers from to with a while loop.
Start the counter, test it, and change it inside the loop.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. Start n = 1. Repeat while n <= 5. Inside the loop, show n and then add 1.
Check. After the number 5, n becomes 6. The condition 6 <= 5 is false, so the loop ends. If we forgot n = n + 1, the loop would never stop.
Log in to join the discussion.
Loading…