Skip to content Skip to sidebar Skip to footer

Changing "for Loop" To "while Loop"

Wondering how would the following for loop be changed to while loop. While having the same output. for i in range(0,20, 4): print(i)

Solution 1:

as simple as that:

i = 0
while i < 20:
    print(i)
    i += 4

Solution 2:

i = 0
while i < 20:
    print(i)
    i += 4

Solution 3:


Solution 4:

i=0
while(i<5):
    print(4*i)
    i+=1

Post a Comment for "Changing "for Loop" To "while Loop""