Hello World!
Part of the Fundamentals section of Coddy's Lua journey — lesson 2 of 90.
The print() function takes whatever you put inside the parentheses and displays it as output. When you want to display text, you need to wrap it in quotes to create what's called a string.
Here's the basic syntax:
print("Your text here")You can use either double quotes " or single quotes ' around your text - both work the same way in Lua.
The traditional first program that every programmer writes is called "Hello World!" and it looks like this:
print("Hello World!")When you run this code, you'll see the exact text Hello World! appear in the output area. This simple program demonstrates the fundamental concept of producing output in any programming language.
Challenge
EasyUse the code view to write a program that outputs
Hello World!
Note that anything inside quotation marks is case sensitive. For example:
print("Hello World!")print("hello world!")are different things (notice the capital letters in the first line).
Cheat sheet
To display text in Lua, use the print() function with the text wrapped in quotes to create a string:
print("Your text here")You can use either double quotes " or single quotes ' around your text:
print("Hello World!")
print('Hello World!')Text inside quotation marks is case sensitive.
Try it yourself
-- TODO: Write your code hereThis lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Operators 2 Relational & Logic
Equality OperatorsRelational OperatorsThe 'and' OperatorThe 'or' OperatorThe 'not' OperatorShort-Circuit EvaluationTruthy and Falsy ValuesRecap - Simple Logic7Basic Conditional Logic
The if-then StatementThe if-then-else StatementThe elseif StatementRecap - Treasure Chest2Variables and Data Types
What is a Variable?NumbersStringsBooleansThe Value 'nil'The type() FunctionNaming ConventionsRecap - Character Profile5Basic Output
Printing LiteralsPrinting VariablesPrinting Multiple ValuesCombining Strings & VariablesThe tostring() FunctionInputCastRecap - Status ReportRecap - Till 1208String Manipulation Basics
string.len()string.upper & string.lowerstring.sub()string.rep()string.find()Recap - Format Username3Operators 1 Arithmetic & Conc
Arithmetic OperatorsModulo OperatorExponentiation OperatorString ConcatenationOperator PrecedenceRecap - Simple Calculations6Project: Character Stats Disp
Welcome MessageDeclare Character Stats9Functions Basics
Declaring a FunctionCalling a FunctionFunctions with ParametersFunctions with Multiple ParamsThe 'return' StatementRecap - Area Calculator