[Home] [Downloads] [Search] [Help/forum]

Register forum user name Search FAQ

logical operators

The logical operators are and, or, and not. Like control structures, all logical operators consider false and nil as false and anything else (including zero) as true. The operator and returns its first argument if it is false; otherwise, it returns its second argument. The operator or returns its first argument if it is not false, otherwise, it returns its second argument.

Both and and or use short-cut evaluation, that is, they evaluate their second operand only when necessary.

A useful technique is to use the ability of or to return its first argument if it is not false to quickly test if a variable exists. For example:

t = t or {} -- create table if it does not exist

The operator not always returns true or false.

See Also ...

Lua keywords/topics

data types
for (generic)
for (numeric)
if / then / else
relational operators
string literals


Lua base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua LPEG library
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua SQLite (database) interface
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting callbacks - plugins

(Help topic: lua=logical operators)

Documentation contents page

Search ...

Enter a search string to find matching documentation.

Search for:   

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]