for / while

numeric for and while.

Numeric for and while.

Goal

Print a running total.

local total = 0
for i = 1, 5 do
  total = total + i
  print(i, total)
end
for i = 1, 3 do
  print(({"Nairobi", "Mombasa", "Kisumu"})[i])
end
local units = {12, 8, 5}
local i = 1
while i <= #units do
  print(units[i])
  i = i + 1
end
for _, city in ipairs({"Nairobi", "Nakuru", "Eldoret"}) do
  if city == "Nakuru" then break end
  print(city)
end