Python - Print numbers from 1-10 using while loop


Python - Print numbers from 1-10 using while loop

CODE
def writeNumbers(): #Initialize the variable i to 1. #This will be starting number that will be printed inside the loop. i = 1 #The While loop prints the number from 1-10. #The condition i <= 10 takes care of exiting from the while loop. while(i <= 10): print(i) #The variable i is incremented by 1 below. #This will take care of printing the next number when the loop is executed next. #This will also take care of exiting from the loop. The loop will be an infinite loop if the below statement is not there. i = i + 1 writeNumbers() #OUTPUT #1 #2 #3 #4 #5 #6 #7 #8 #9 #10

Comments