Lesson 7 of 15
For Loops
Numeric For
The numeric for loop iterates from a start to a stop value:
for i = 1, 5 do
print(i)
end
-- prints 1, 2, 3, 4, 5
You can specify a step:
for i = 0, 10, 2 do
print(i)
end
-- prints 0, 2, 4, 6, 8, 10
Counting down with a negative step:
for i = 5, 1, -1 do
print(i)
end
-- prints 5, 4, 3, 2, 1
Your Task
Use a for loop to print the even numbers from 2 to 10.
JS Transpiler loading...
Loading...
Click "Run" to execute your code.