A while loop allows us to repeat an action until a certain condition is met.

While loops are similar to if statements. An if statement executes code if a condition is true. A while loop will keep repeating its code while a condition is true.

The code for a while loop might look like this:

While (I am not home) { Take step toward home }

While loops allow us to move towards a goal until it is reached. Let’s practice!


Can you help Codey reach the flag? Use the while loop and movement blocks to make Codey move toward the goal until they reach it.

Combine the while loop and the condition, and place the move blocks inside of the loop.
While Codey has not reached goal Move right

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?