function myFunction()def myFunction()func myFunction()declare myFunction()myFunction()call myFunction()execute myFunction()invoke myFunction()functiondefinefuncdeclaremyFunction(arg1, arg2)myFunction[arg1, arg2]myFunction{arg1, arg2}call myFunction(arg1, arg2)exitendreturnstopreturnexitoutoutputnilreturn 1, 2, 3return (1, 2, 3)return {1, 2, 3}return [1, 2, 3]var1, var2 = myFunction()var1 = myFunction()var1 <- myFunction()var1 + myFunction()return statement in Lua?
falsenil0""nil as default valuesend to close the functionlocal varName = valuedef varName = valuevariable varName = valuevar varName = valueglobal keywordlocal?
global varName = valuevarName = valuelocal varName = valuedefine varName = valueglobal keywordlocalsetglobal keywordglobalglobal variable = valuelocal keywordsetglobal| Qno | Answer |
|---|---|
| 1 | a) function myFunction() |
| 2 | a) myFunction() |
| 3 | a) function |
| 4 | b) An error is thrown |
| 5 | b) No, functions must be defined first |
| 6 | a) myFunction(arg1, arg2) |
| 7 | b) end |
| 8 | a) Yes, they can return multiple values |
| 9 | c) Both by value and reference |
| 10 | a) Yes, if the function is defined without arguments |
| 11 | a) Using return |
| 12 | a) Returns nil |
| 13 | c) All values are returned as separate results |
| 14 | a) return 1, 2, 3 |
| 15 | a) Using var1, var2 = myFunction() |
| 16 | b) nil |
| 17 | a) Yes, by using nil as default values |
| 18 | a) Passing too many arguments |
| 19 | b) A variable that is accessible only within the function or block where it is defined |
| 20 | a) local varName = value |
| 21 | b) No, local variables are confined to their scope |
| 22 | b) Local variables are always private and cannot be accessed globally |
| 23 | a) Global |
| 24 | b) varName = value |
| 25 | b) Assign a value to a variable without using local |
| 26 | a) The local variable will overwrite the global variable |
| 27 | a) Yes, global variables are always accessible |
| 28 | b) They can create conflicts and make code harder to debug |
| 29 | b) By assigning a new value to the variable without the local keyword |
| 30 | b) To limit variable scope and reduce potential conflicts |