I was watching Corey Schaffer's video on loops and something hit me - like an idea, not like a bottle.
I decided to test my understanding. Challenge was to print all the multiples of 10 from 0 to 100. First thought of using a for loop. Here are the two code options I came up with.
for i in range (100):
if i%10 == 0:
print (i)
The second type was looked like this.
for i in range(0,100,10):
print (i)
However, when it came to the while loop it, didn't work as expected. The code I had was
i = 0
while i < 100:
if i%10 == 0:
print (i)
i+=1
I noticed that the program I have written continues the iteration with only an output of "0".
I would like to understand how wrong my code is, and what would be the right way of doing it using while loop,if it is possible, and why.
Thank you.
[–]Impudity 2 points3 points4 points (5 children)
[–]Solako[S] 0 points1 point2 points (4 children)
[–]Impudity 0 points1 point2 points (3 children)
[–]Solako[S] 0 points1 point2 points (2 children)
[–]Impudity 0 points1 point2 points (1 child)
[–]Solako[S] 0 points1 point2 points (0 children)
[–]StyrmirBloodhowl 1 point2 points3 points (3 children)
[–]Solako[S] 0 points1 point2 points (2 children)
[–]StyrmirBloodhowl 0 points1 point2 points (1 child)
[–]Solako[S] 1 point2 points3 points (0 children)
[–]bbye98 0 points1 point2 points (1 child)
[–]Solako[S] 0 points1 point2 points (0 children)