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:

It will be something like this:

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

you can also visit here for more info: https://www.w3schools.com/python/python_while_loops.asp

Solution 4:

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

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