- Trending Categories
- Data Structure
- Operating System
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- 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
- PHP continue Statement
- Continue Statement in C/C++
- Java continue statement with Loop
- Continue statement in Dart Programming
- Continue Statement in C/C++ Programming
- Break statement in Lua Programming
- Return statement in Lua Programming
- How to use continue statement in Python loop?
- Why does clinical thermometer not have alcohol ?
- Inline conditions in Lua (a == b ? “yes” : “no”)
- Why does our urine does not have any blood cell?
- Why do teenagers feel they have only rights and no responsibilities?