while loop and if statement python code example

Example 1: while loop in python

j = 0
while j < 3:
  print("hello") # Or whatever you want
  j += 1
#This runs the loop until reaches 3 and above

Example 2: 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.

Example 3: while loop in python

#Make a variable containing an integer like shown below:
i=1
while i<=6:
  print ("Hello")
#This loop will go on forever and the only way to stop it is to kill your program