

whether it is or not, it keeps printing the value of i and reducing it by 1 until it is.

PYTHON WHILE LOOP PYTHON NOT EQUAL CODE
When the value of i finally equals 0, the interpreter pauses running the code block and checks once more to see whether the value of i=0. It now displays the value of i (i=9) before setting it once more to i=i-1 (i = 9-1 = 8).

The interpreter resumes running the code block since the value of i is 9. The interpreter now determines if i=0 or not. As a result, i now have a value of 10-1 which is 9. The value of i is set to i-1 in this line. The interpreter then reads the next line, which is i-=1, after printing the value of i. As a result, the interpreter repeats printing the value of i until the value of i equals 0, at which point it exits the loop.Ĭonsequently, the value we specify for i, which is 10, is the first value printed. We print the value of i and then each time decrease its value by 1 in the code block contained within the loop. i.e., until the value of i is not equal to 0, the interpreter will execute the block of code. After that, a while loop was initiated with the constraint that i!= 0. Output:- Code And Output For A Simple While Loop Programįirst, we set “i” in the example above to have a value of 10. # looping the code block until the value of i is not equal 0 I = 10 #declaring a variable i with value 10
