print and io.write
Lua has two ways to show output: print and io.write. You will use print most of the time, but each one is useful.
print can take more than one value. Separate the values with commas:
print("Name:", "Alice")
print(1, 2, 3)
Output:
Name: Alice
1 2 3
print puts a tab character between the values. A tab is one wide gap, not a group of spaces. After the last value, print ends the line, so the next output starts on a new line.
If you call print with nothing inside the parentheses, it prints an empty line:
print("Line 1")
print()
print("Line 3")
Output:
Line 1
Line 3
io.write
io.write prints exactly what you give it. It adds no tabs between values and does not end the line. So several calls can build one line, piece by piece:
io.write("loading")
io.write("...")
io.write("done\n")
Output:
loading...done
The line ends only because the last call has \n at the end of its text. Use io.write when the exact shape of a line matters, for example when you build one line in several steps.
Escape sequences
Inside a string, a backslash \ starts an escape sequence: a short code for a character that is hard to type. \n is a new line, \t is a tab, and \" is a quote mark inside a string that uses double quotes.
print("Line 1\nLine 2")
print("A\tB")
print("She said \"hi\"")
Output:
Line 1
Line 2
A B
She said "hi"
In the exercise, finish one line with print and one line with two io.write calls.