Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Short circuit evaluation (lazy operator) in Lua

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 ...

function agelimit(incoming)
return type(incoming) == "number" and incoming or 18
end
-- And the code to call that function ...
print (agelimit(10))
print (agelimit(12))
print (agelimit("fourteen"))
print (agelimit(16))


And when you run that, you get ...

[trainee@easterton u106]$ lua lazy
10
12
18
16
[trainee@easterton u106]$





If you're wanting to learn to program in Lua and you're looking for a training course, please ask us (email info@wellho.net). 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 articles
U106 - Lua - Functions.
  [1697] Sorting in lua - specifying your own sort routine - (2008-07-05)
  [1699] If you are learning Lua, here are some more examples - (2008-07-06)
  [1743] First class functions in Lua lead to powerful OO facilities - (2008-08-07)
  [1744] Lua examples, Lua Courses - (2008-08-08)
  [1847] Lua - IAQ (Infrequently Answered Questions) - (2008-10-18)
  [2312] What are closures in Lua? - (2009-07-31)
  [2347] Dot, dot, dot in Lua - variable length parameter lists - (2009-08-11)
  [2356] Passing multiple results back from a function - Lua, Python, etc - (2009-08-13)
  [2455] Lua examples - coroutines, error handling, objects, etc - (2009-10-15)
  [2723] Returning multiple values from a function - Lua - (2010-04-15)
  [2949] Lua - variable function arguments and select - (2010-09-08)
  [3695] Functions are first class variables in Lua and Python - (2012-04-13)

U103 - Lua - Conditionals and loops
  [1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
  [1738] Clean code, jump free (Example in Lua) - (2008-08-06)
  [2351] Ternary operators alternatives - Perl and Lua lazy operators - (2009-08-12)
  [2454] For loops in Lua - (2009-10-14)
  [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
  [3558] Python or Lua - which should I use / learn? - (2011-12-21)
  [3686] The goto statement in Lua - (2012-04-06)
  [4272] Lazy operators in Lua - what they mean, and examples - (2014-05-05)
  [4322] Learning to Program - the conditional statement (if) - (2014-11-21)
  [4323] Learning to program - Loop statements such as while - (2014-11-22)
  [4574] repeat until in Lua - a one or more rather than a zero or more loop - (2015-11-05)


Back to
Two PHP include files to make easy web site indexing and navigation
Previous and next
or
Horse's mouth home
Forward to
FTP - how not to corrupt data (binary v ascii)
Some other Articles
Some sideways thoughts on the news
cannot restore segment prot after reloc message - PHP / httpd
Virtual Hosting on Apache httpd - a primer example
FTP - how not to corrupt data (binary v ascii)
Short circuit evaluation (lazy operator) in Lua
Two PHP include files to make easy web site indexing and navigation
Plenty of car parking at Well House Manor, Hotel, Melksham
Accounts in PHP - an OO demo
Adding a button to a web page to print the page
Astroturfing - the online definition
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/1685_.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb