Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

else

What happens when none of the if or elseif statements evaluate to true? No chunk of code is executed. But, you might want some chunk of code to execute when none of the if/elseif arguments are true. This is what the else statement does. It executes a chunk of code when none of the statements tested by the preceding if/elseif tests were true.

Syntactically, the else statement is just an else/end chunk. The else statement always comes last, as demonstrated by the following code:

print ("Enter your name")name = io.read()if #name <= 3 then    print ("that's a short name, " .. name)elseif #name <= 6 then    print (name .. " is an average length name")else    print ("that's a long name, " .. name)end

There can be only one else statement, and it must ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content