In Lua, if a partial expression evaluates to true the following section will NOT be evaluated if it follows an or because the whole thing cannot be true.
If a partial expression evaluates to false, the following section will NOT be evaluated if it follow an and because the whole thing must be true.
If you find this a bit theoretic, try a real life example ...
If you're going to buy a kebab OR Fish and Chips and you find the kebab shop open, you won't bother to carry on up the road to the chippy because you have already met your needs.
If you require a hammer AND nails, but you can't find a hammer, you won't go and search for the nails because even if you find them, they're not going to be much use to you!
Let's see some code ...
return type(incoming) == "number" and incoming or 18
-- And the code to call that function ...
And when you run that, you get ...
[trainee@easterton u106]$ lua lazy
If you're wanting to learn to program in Lua and you're looking for a training course, please ask us (email email@example.com
). Although we're not [yet?] offering a scheduled public course, we are running private courses for two different groups:
• Delegates with no prior programming experience
• Delegates who have programming experience, but are new to Lua.
Course can be run for groups of 3 to 10 delegates, and vary in length from 2 to 4 days depending on the background of the delegates, the size of the class, and just how deep you want us to go into certain aspects.
Some sample quotations:
• At our training centre - Melksham, Wiltshire, England
• At your office in the UK - example - Coventry, England
• At your office in the Ireland - example - Dublin
• At your office in the USA - example - New York State (written 2008-06-22, updated 2008-06-23)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesU103 - Lua - Conditionals and loops 
Learning to program - Loop statements such as while - (2014-11-22) 
Learning to Program - the conditional statement (if) - (2014-11-21) 
Lazy operators in Lua - what they mean, and examples - (2014-05-05) 
The goto statement in Lua - (2012-04-06) 
Python or Lua - which should I use / learn? - (2011-12-21) 
Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18) 
Lua examples - coroutines, error handling, objects, etc - (2009-10-15) 
For loops in Lua - (2009-10-14) 
Ternary operators alternatives - Perl and Lua lazy operators - (2009-08-12) 
Clean code, jump free (Example in Lua) - (2008-08-06) 
Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)U106 - Lua - Functions. 
Functions are first class variables in Lua and Python - (2012-04-13) 
Lua - variable function arguments and select - (2010-09-08) 
Returning multiple values from a function - Lua - (2010-04-15) 
Passing multiple results back from a function - Lua, Python, etc - (2009-08-13) 
Dot, dot, dot in Lua - variable length parameter lists - (2009-08-11) 
What are closures in Lua? - (2009-07-31) 
Lua - IAQ (Infrequently Answered Questions) - (2008-10-18) 
Lua examples, Lua Courses - (2008-08-08) 
First class functions in Lua lead to powerful OO facilities - (2008-08-07) 
If you are learning Lua, here are some more examples - (2008-07-06) 
Sorting in lua - specifying your own sort routine - (2008-07-05)
Some other Articles
Some sideways thoughts on the newscannot restore segment prot after reloc message - PHP / httpdVirtual Hosting on Apache httpd - a primer exampleFTP - how not to corrupt data (binary v ascii)Short circuit evaluation (lazy operator) in LuaTwo PHP include files to make easy web site indexing and navigationPlenty of car parking at Well House Manor, Hotel, MelkshamAccounts in PHP - an OO demoAdding a button to a web page to print the pageAstroturfing - the online definition