Created
December 4, 2021 04:35
-
-
Save rozer007/c40b8ef66c7d5bd0dcf7cd03a0af23a0 to your computer and use it in GitHub Desktop.
Loops in lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1. Does lua have continue keyword ? | |
ans : NO,we can use goto to work like a continue keyword. | |
Q2. What does break statement do? | |
ans: This will terminate the loop. | |
Q3. What type of loop in lua is similar to do while loop in other language? | |
ans: repeat until loop is pretty muat similar to do while since it check the condition after the execution. | |
Q4. what is the syntax of foreach loop in lua for iterating a table? | |
ans: | |
for key,value in table do | |
--body | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q1. What will be the output of this statement: | |
for i=1,,1 do | |
print("pep"); | |
end | |
a) error | |
b) pep | |
pep | |
pep | |
c) infinite loop | |
d) | |
ans: a) | |
Q2.how many time will this loop run ? | |
int i=0; | |
repeat{}until(i>0); | |
a) 0 | |
b) infinite | |
c) 1 | |
d) error | |
ans: b) | |
Q3. Q3) what will the output of this code: | |
i=1; | |
repeat | |
io.write(i); | |
if(i==4)then break end | |
i=i+1; | |
until(i<=5); | |
a) 1 | |
b) 13 | |
c) infiniteloop | |
d) none of the above | |
ans: a) | |
Q4. Output of this code? | |
fori= 1,5,1 do | |
io.write(i) | |
if(i==2) then continue end | |
end | |
a) 1345 | |
b) 1 345 | |
c) error | |
d) None of the above | |
ans: c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment