S T
S T

Reputation: 13

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)

Upvotes: 0

Views: 66

Answers (4)

Noohone
Noohone

Reputation: 724

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

Upvotes: 0

roozbeh S
roozbeh S

Reputation: 1124

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

Upvotes: 0

void
void

Reputation: 2533

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

Upvotes: 1

hiro protagonist
hiro protagonist

Reputation: 46859

as simple as that:

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

Upvotes: 1

Related Questions