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

Comments

Comments are notes for humans that Lua ignores when the program runs.

In this page:

  1. Comments

Comments

A single-line comment starts with two dashes and lasts until the end of the line. A block comment starts with --[[ and ends with ]]. Comments can be used to explain code or temporarily disable it.

Note: Adding another dash to the opening, as in ---[[, turns a block comment off with a single character.

Example: Comments

lua
-- this is a single-line comment
print("visible") -- comment after code

--[[
print("this line is commented out")
print("and so is this one")
]]

--[==[ a block that may contain ]] safely ]==]
print("done")

-- Output:
-- visible
-- done
Common Mistakes
  1. Using // or # for comments like other languages
  2. Forgetting the closing ]] of a block comment
  3. Nesting block comments without using level markers such as --[=[
Chapter Summary
  • -- starts a line comment
  • --[[ ]] makes a block comment
  • Comments are ignored by Lua
  • Level markers like --[==[ allow ]] inside comments
🔒

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.