Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
The 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 z=1,10 do
     for y=1,10 do
        for x=1,10 do
           if x^2 + y^2 == z^2 then
              print('found a Pythagorean triple:', x, y, z)
              goto done
           end
        end
     end
  end
  ::done::


You cannot jump into an inner scope which includes local variables, and there are some further (sensible) limitations. This use of the goto to get out of multiple nested loops save you a whole series of nested checks or booleans.

There's a complete example showing sample output too [here].
(written 2012-04-06, updated 2012-04-07)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
U198 - New in Lua 5.2
  [3683] Weak references in Lua - what are they, and why use them? - (2012-04-04)
  [3687] Binary / bitwise operations in Lua with the standard bit32 library - (2012-04-06)
  [3690] Changes in Lua 5.2 - Garbage Collection - (2012-04-08)

U103 - Lua - Conditionals and loops
  [1685] Short circuit evaluation (lazy operator) in Lua - (2008-06-22)
  [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)
  [2455] Lua examples - coroutines, error handling, objects, etc - (2009-10-15)
  [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)
  [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
Programming Standards in Lua
Previous and next
or
Horse's mouth home
Forward to
Binary / bitwise operations in Lua with the standard bit32 library
Some other Articles
Can I cycle or ride my mobility scooter on the pavement?
Shopkeepers take an Easter break too
The goto statement in Lua
Programming Standards in Lua
Once upon a Maundy Thursday
Melksham Business Newsreel
Kicking up a stink, the Victorian way?
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., 2021: 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/3686_The ... n-Lua.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb