Declaring and using loops
Loops are valuable components when it comes to programming, especially when working with sets of data. It would, of course, be quite unrealistic to expect a programmer to index and assign all one thousand elements of a hypothetical table to variables in order to perform some sort of operation. To accomplish behaviors like this, loops are key. These loops function by jumping back to the beginning of their code block if a condition is still met, executing until they reach their terminating case.
For loops
for
loops are a type of loop that are primarily used for iterating over datasets. In Lua, those datasets are typically related to tables or numbers. In Lua, there are two types of for
loops: numeric for
loops and generic for
loops. The primary difference between these is what determines how they are executed. For numeric for
loops, a variable is assigned to a defined start value, end value, and optionally an increment value; if the increment is not included...