Computer Science, asked by Singeryash, 10 months ago

rewrite the following code using for loop
i=100
while i>0:
i=i-1
if i==20:
break

Answers

Answered by rani49035
0

Explanation:

we can use for loop

.

.

for(i=100;i>0;i--)

{ if(i==20)

{ break;}

}

.

.

.

hope this will help you

Answered by AskewTronics
0

Following code are repeated code in Python using for loop :

Explanation:

for i in range(100,0,-1):  #for loop which replace the above while loop.

   if i==20: #it is taken from the above code.

       break#it is also taken from the code.

Code Explanation:

  • The above code is written in a python language, which is a modified form of the question code. This modification is done by the help of replacing for loop in the place of while loop.
  • The while loop will run from 100 to 20, then the for loop also runs from 100 to 20.
  • It is because when the value of i will be 20, then the break statement will be called and the loop gets terminated.

Learn More :

  • Python : https://brainly.in/question/14689905

Similar questions