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

Logical operators

Logical operators test the relationship of two statements. Logical operators work a little differently in Lua than in other languages. In Lua, anything not false is considered to be true. Only two values represent false for a logical operator, the constant value of false and nil; anything else is true.

Logical operators in Lua do not evaluate to a Boolean result; rather they evaluate to one of the provided operands.

The and operator returns its first operand if that operand is false and the second operand if the first operand was true. Here is an example:

x = true and false -- value is falsey = false and false -- value is falsez = true and true -- value is truew = 7 and 1 -- value is 1

The or operator (or) returns its second ...

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