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

Nesting if statements

if/elseif/else statements control the execution of chunks of code. Like chunks, if statements can be nested. The same rule for scope applies to nested if statements as it does to nested chunks. The following code demonstrates the use of nested if statements:

print ("Enter a number")x = io.read()if x == "6" then    print ("x is six!")    print ("Enter another number")    local y = io.read()    -- Nested if statement begins here    if y == "6" then        print ("y is also six!")    elseif y == "5" then        print ("y is one less than x")    else        print ("x is 6, but y is not!")    end    -- Nested if statement ends hereelse     print ("x is not 6!" .. x)end
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