Lua Loops- Lua nested loops - Lua (programming language)

What is the use of Lua nested loops?

Lua programming language allows in using one loop inside another loop. Below section shows few examples to illustrate the concept.

Syntax

Syntax for a nested for loop statement in Lua is as follows

The syntax for a nested while loop statement in Lua programming language is as follows

The syntax for a nested repeat...until loop statement in Lua programming language is as follows

A final note on loop nesting is that you can put any type of loop inside of any other type of loop. For example, a for loop can be inside a while loop or vice versa.

Example

Below program uses a nested for loop

When you build and run the above code, it produces the following result.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Lua (programming language) Topics