Mukul Latiyan has Published 474 Articles

While loop in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:58:07

542 Views

A while loop is an indefinite loop that can be modified to run for a finite number of iterations based on the condition we provide.In Lua, the while condition is tested first. If the condition turns out to be false, then the loop ends, otherwise, Lua executes the body of ... Read More

Variable number of arguments in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:50:06

3K+ Views

There are functions in Lua that accept a variable number of arguments. These are very helpful in cases where we want to run the same function with many different arguments that might vary in length. So, instead of creating a different function, we pass them in a variable arguments fashion.Syntaxfunction ... Read More

Table Type in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:46:45

1K+ Views

A table is a data type in Lua, which is used to implement associative arrays. These associative arrays can be used to implement different data structures like queues, maps, lists, etc.An associative array in Lua is an array that can be indexed not only with numbers, but also with strings ... Read More

Return statement in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:44:34

4K+ Views

There are certain cases where we want to return a value from a given function so that we can use it later. These return values make use of a return keyword which in turn allows a function to return values.There is an implicit return at the end of any function, ... Read More

Numeric for in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:42:21

706 Views

In Lua, there are two types of for loops − the numeric for and the generic for.SyntaxThe numeric for uses the following syntax −for var=exp1, exp2, exp3 do something endIt should be noted that we can write exp1, exp2, exp3 at the same time or we can ... Read More

Named Arguments in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:36:33

930 Views

We know that when we pass arguments to a function in any programming language, they are matched against a parameter. The first argument’s value will be stored in the first parameter, the second argument’s value will be stored in the second parameter, and so on.ExampleConsider the example shown below −local ... Read More

If-then-else in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:32:59

2K+ Views

An if statement in Lua is used to evaluate some code based on some conditions. If those conditions match, then we execute the code that is written inside the code block of an if statement, else we do nothing.In Lua, the if statement tests its condition and if that condition ... Read More

Global Variables in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:29:49

7K+ Views

Global variables in Lua are the variables that don’t need any type of declaration in them. We can simply define the name of the variable and assign any value we want to it, without having to use any keyword with it.Having global variables makes certain programming cases possible, and it ... Read More

Generic for in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:28:47

650 Views

The generic for in Lua allows us to iterate over the values in an iterator fashion; it is much more powerful even though it looks simple. The Lua library has plenty of iterators, over which we can use the generic for loop.Syntaxfor i, v in pairs(x) do ... Read More

Comments in Lua Programming

Mukul Latiyan

Mukul Latiyan

Updated on 01-Dec-2021 10:15:39

15K+ Views

Comments are a set of commands that are ignored by the compiler. They are used in a scenario where you want to attach a note to your code or a section of code so that when you visit it later, you can recall it easily. The comment statements are usually ... Read More

Advertisements