Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact

Well House Consultants
You are on the site of Well House Consultants who provide Open Source Training Courses and business hotel accommodation. You are welcome to browse and use our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Java Resources
Well House Manor Resources
Perl Resources
Python Resources
PHP Resources
Object Orientation and General topics
MySQL Resources
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
Extras Resources
C and C++ Resources
Ruby Resources
Tcl/Tk Resources
Web and Intranet Resources
Lua module U103
Conditionals and loops
Exercises, examples and other material relating to training module U103. This topic is presented on public courses Learning to program in Lua, Lua Programming




Articles and tips on this subjectupdated
3397Does a for loop evaluate its end condition once, or on every iteration?
All the languages that we teach have a for loop or the equivalent, which is a clean way of repeating a block of code with a rising or falling index number. It's used in many circumstances - for example in iterating through the months of the year (for m goes from 1 to 12) of in stepping through all ...
2012-04-15
 
3686The goto statement in Lua
In the past there was considerable debate in academia and industry on the merits of the use of goto statements, and indeed Lua didn't have them until release 5.2. Well used in Lua, they can provide an escape from inner loops, jumping to a label using a ::label:: format. For example:   for ...
2012-04-07
 
3558Python or Lua - which should I use / learn?
"Should I learn and use Python or Lua" - a question to me. The questioner was perceptive, knowing that he shouldn't try to learn lots of languages at the same time, and that he should always limit the "basket" of languages used within his applications - in fact, he was wondering if he could select just ...
2011-12-24
(longer)
2454For loops in Lua
As an old Fortran programmer, I remember that a for loop was given a start point, an end point and a step ... and they had to be whole numbers (integers). Lua's for loops can be used that way, but they can be used a lot more flexibly too. From, to, step for loops Th egood news is that Lua works in ...
2009-10-17
 
2455Lua examples - coroutines, error handling, objects, etc
I have presented a bespoke Lua course over the last three days ... and it has lead me to some interesting new examples which I'm sharing here. Object Orientation is more a way of thinking and coding than a language feature in Lua - when you set up a piece of data / structure / object, you do so in a ...
2009-10-17
 
2351Ternary operators alternatives - Perl and Lua lazy operators
"If the gender is male, the answer is him, but if the gender is female, the answer is her". A common situation in programming - [is/are], [him/her], [yes/no], [child/children], [ice/water/steam], [public/private] - and C and Perl and PHP provide the "ternary" operator ? and : to provide a shorthand ...
2009-08-12
 
1738Clean code, jump free (Example in Lua)
The "goto" statement - in languages that still support it - is regarded with disdain by Computer Scientists as it makes for spaghetti code - hard to follow and going all over the place! In some ways, loop controls "break" and "continue" ("last", "next" and "redo" in Perl; "next", "redo", "retry" and ...
2008-08-07
 
1696Saying NOT in Perl, PHP, Python, Lua ...
"Isn't there one standard way to say NOT?" asked one of my delegates on today's course - and it's an excellent question. But the answer to a question about a negative subject is itself in the negative - no, there isn't just a single way! In fact .. I can think of no fewer that 12 ways! • 1. ! ...
2008-07-05
 
1685Short 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 ...
2008-06-23
 
Examples from our training material
andor   Lazy and / or operators
bpm   string.find v string.gfind
clike   for loop with pairs and ipairs
clumpit   for loop termination
doco   Changing loop counts
exa   Loops and conditionals - exchange rate example
floo   for loop in which end condition changes
kz   Example of a for loop
lif   if, elseif, else
ll2   while loop and repeat until loop
lloops   while and for loops
lsx   Lua for loop - termination
swans.lua   Swan family - Lua
tchart   for loop with start, end and step
wcd   Comparison of while and until loops
whilly   Writing cleaner code without break or continue
Background information
Some modules are available for download as a sample of our material or under an Open Training Notes License for free download from http://www.training-notes.co.uk.
Topics covered in this module
If while repeat break do and for.
Comparing numbers comparing strings.
Equality and nil.
Combining Conditions.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule page.

Well House Consultants specialise in training courses in Python, Perl, PHP, and MySQL. We run Private Courses throughout the UK (and beyond for longer courses), and Public Courses at our training centre in Melksham, Wiltshire, England. It's surprisingly cost effective to come on our public courses - even if you live in a different country or continent to us.

We have a technical library of over 700 books on the subjects on which we teach. These books are available for reference at our training centre. Also available is the Opentalk Forum for discussion of technical questions.


You can Add a comment or ranking to this page

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

PAGE: http://www.wellho.net/resources/U103.html • PAGE BUILT: Wed Mar 6 10:39:20 2013 • BUILD SYSTEM: wizard