Consider the following Lua code:
local var1, var2;
Is var2
a local variable here? Or is only var1
a local?
Do not declare more than one variable per declaration. Every declaration should be for a single variable, on its own line, with an explanatory comment about the role of the variable. Declaring multiple variables in a single declaration can cause confusion regarding the types of the variables and their initial values.
If your variables are the same type, you can define multiple variables in one declaration statement. For example: int age, reach; In this example, two variables called age and reach would be defined as integers.
Another way to assign multiple variables using a command's output is to assign the command output fields to an array. In the example, we used the Bash built-in readarray command to read the date command's output. The default delimiter used by the readarray command is a newline character.
You can assign the same value to multiple variables by using = consecutively. This is useful, for example, when initializing multiple variables to the same value. It is also possible to assign another value into one after assigning the same value.
Both are local.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With