- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why does Lua have no “continue” statement?
There’s no continue statement in Lua, and it’s not because the developers of the Lua programming language felt that it is of no use, in fact, in the official documentation they mentioned “continue was only one of a number of possible new control flow mechanisms”. This clearly shows that the developers of the Lua programming language aren’t a huge fan of the “continue” statement.
If we need to break it down the fact that why Lua developers doesn’t wanted a “continue” statement, then it comes down to two possible answers, these are −
- They think that the “continue” statement is just another control flow mechanism and its work can be done by using other statements or a combination of other statements.
- They wanted to make the language more lightweight.
Yes, it is true that the work that a “continue” statement does can be done using a goto statement.
Let’s explore a simple yet powerful and important code where we will make use of the goto statement that will help us to replicate the work that a continue statement does.
Consider the example shown below −
-- prints even numbers in [|1,10|] for i=1,10 do if i % 2 == 1 then goto continue end print(i) ::continue:: end
In the above code, I used the goto keyword that will jump the control over to the ::continue:: keyword as soon as the condition i % 2 == 1 evaluates to true, and hence the loop will skip all the odd numbers and only the even numbers will be printed to the terminal.
2 4 6 8 10
- Inline conditions in Lua (a == b ? “yes” : “no”)
- Does Python have “private” variables in classes?
- To “user-scalable=no” or not to “user-scalable=no” in HTML5
- What does a “set+0” in a MySQL statement do?
- PHP continue Statement
- Why does MySQL evaluate “TRUE or TRUE and FALSE” to true?
- C++ Program to Print “Even” or “Odd” without using conditional statement
- C Program to print “Even” or “Odd” without using Conditional statement
- Java continue statement with Loop
- Continue Statement in C/C++