Answers for "when to use while and if python"

22

how to write a while statement in python

myvariable = 10
while myvariable > 0:
  print(myvariable)
  myvariable -= 1
Posted by: Guest on January-08-2020
3

while else python

target = 100
current = 0

while current != target: 
  current += 1
  print(current)
  
#The while loop repeats the indented code while its condition is true
#(current IS NOT equal to target).
  
else:
  print("Target Reached!")
  
#When the while loop condition is no longer true (current IS equal to target),
#the indented code under else: is ran.
Posted by: Guest on September-01-2020

Code answers related to "when to use while and if python"

Python Answers by Framework

Browse Popular Code Answers by Language