← Back to Lua Course | Chapter 1: Introduction | Lesson 3 of 7

Your first program

A Lua program is just a text file of instructions that print, calculate and decide.

In this page:

  1. Your first program

Your first program

A Lua script is a plain text file, usually ending in .lua, run from top to bottom. The function print writes its arguments to the screen followed by a newline. Strings are written between quotes and joined with the .. operator.

Note: Save scripts with the .lua extension so editors recognise them.

Example: Your first program

lua
local name = "World"
print("Hello, " .. name .. "!")
print("2 + 3 =", 2 + 3)

-- Output:
-- Hello, World!
-- 2 + 3 =	5
Common Mistakes
  1. Forgetting the parentheses after print in a call with several arguments
  2. Using + instead of .. to join strings
  3. Mismatching the opening and closing quotes
Chapter Summary
  • A script runs from top to bottom
  • print adds a newline
  • Strings use single or double quotes
  • .. joins strings
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.