Comments
Comments are notes for humans that Lua ignores when the program runs.
In this page:
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
-- 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
Login to try C/C++/Java/PHP code in the editor
Common Mistakes
- Using // or # for comments like other languages
- Forgetting the closing ]] of a block comment
- 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: