Lesson 6 of 15

While & Repeat

While Loop

The while loop checks its condition before each iteration:

local i = 1
while i <= 5 do
  print(i)
  i = i + 1
end

Repeat-Until

The repeat loop checks its condition after each iteration (like do-while in other languages):

local i = 1
repeat
  print(i)
  i = i + 1
until i > 5

The body always runs at least once.

Your Task

Use a while loop to print the numbers 1 through 5, one per line.

JS Transpiler loading...
Loading...
Click "Run" to execute your code.