The condition is the expression that decides whether the loop is going to continue being executed or not. There are 5 steps to this program:

  1. The loop_condition variable is set to True

  2. The while loop checks to see if loop_condition is True. It is, so the loop is entered.

  3. The print statement is executed.

  4. The variable loop_condition is set to False.

  5. The while loop again checks to see if loop_condition is True. It is not, so the loop is not executed a second time.



See how the loop checks its condition, and when it stops executing? When you think you’ve got the hang of it, click Run to continue.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?