you can start with while counter < 100:
One of the key aspect of writing while loops is watching your counters. For instance, when you type while counter < 100:
If you don’t increase counter in every loop it will create an infinite loop as counter will stay the same and always below 100. Eventually you’ll get a runtime error.
So defining i before the loop:
counter = 0
And increasing i inside the loop:
counter = counter+1
are key points in most while loops.
This can be confusing for absolutely new programmers but you also need another counter which adds up the numbers during the iteration.
With some repetition and pondering you will definitely get a grip of while loops, it’s normal to struggle with them slightly more than for loops which usually doesn’t have to bother with counters for the loop to function properly.
So,
total = 0
before the loop;
and,
total = total+counter
inside the loop will ensure that total adds each number to the sum along the way during the iteration.
while counter <= 100:
total= total+counter
counter= counter+1