Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

Nested loops

Much like control structures, loops operate on a chunk of code. Also, similar to control structures, loops can be nested. You can nest different types of loops within each other. The same scope rules apply to nesting loops as to everything else so far.

If you have a break statement, it will only break one loop, the innermost loop closest to the statement. The following piece of code demonstrates breaking out of nested loops:

for i = 0, 10 do    local j = 0    while j < 10 do        print ("j: " .. j) -- Will never be > 2        if j == 2 then            print ("j is: " .. j .. ", i is:" .. i)            break        end        j = j + 1    endend
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content