Updated April 10, 2023
Introduction to Lua continue
Lua continue is one of the statement and is mainly used for to execute the loop conditions in further ways or steps to continue the conditions it may be any validation or authenticating the user inputs its nothing but a keyword continue to be existed its have some restriction semantically to be authenticated for all the variables, keywords and default functions so these comes under the validation scope for to checking the user inputs and enforced to the lua compiler so mainly the workaround is to invert the loop conditions that would be the cause of the conditional statements like continue for to rest of the loop body statements.
Syntax:
In lua script we have n number of loops, conditional statements is used for to implement the application depends upon the requirement getting by the user end. Like that lua does not have the “continue” keyword instead of that we have do break end the statement will never ends still they have some implements waiting for the script execution.
Loops(for, while ) do repeat //do and repeat are keywords
Conditional statements(if) variables for to checking the conditions then //then is the keyword
do break end // it simulates to continue
goto skip_to_next
--some lua scripts depends upon the requirement----
Above codes are the basic looping statements which is used for to evaluate and iterate the input values on the script.
Flowchart
The flowchart is the pictorial representation of the document which is used for to getting the project details easily understand. Here the Lua “continue” keyword which is used for similar looping conditions and other built-in functions.
How continue Statement Works in Lua?
- The continue keyword is not having the lua scripts instead of that we used do break end statements for to continue the statements which is going to be execution of the next level on the script. Why we don’t use the continue keyword because it’s a lightweight design instead of continue we use goto statement and keyword for to continue further on the script.
- When we use goto statement the keyword which is used for still it can be on the supported it and mainly regards that it can be applicable for the scientific application so it’s a spaghetti code and its hardly focus on the follows which finds and replace the words for all over the areas which is used on the script requirement. In other ways like loop controls will be used as the break and continue keywords on other languages like perl and python codes.
- Its not comes under repeat until loop conditions are completed on the script because whenever we execute the loop statement like while loop it always execute first whenever the condition is to be satisfied or else it terminates the loop. But when we use do while statement the loop is executed first once on the script and then its evaluate the conditions if its true it execute the loop or else it terminates the loop and continue with further steps.
Examples of Lua continue
Given below are the examples of Lua continue:
Example #1
Code:
function demo(vars1, vars2)
return vars1 + vars2
end
print(string.format("124 + 241 = %d", demo(124,241)))
function demo1(vars3)
vars4 = {}
local i = 6
for str in string.gmatch(vars3, "[^%s]+") do
vars4[i] = str
i = i + 1
end
return vars4, i
end
vars5, vars6 = demo1("Welcome To My Domain its a first example for continue statement of the lua script")
for j = 1, vars6 do
print(string.format("%d : %s", j, vars5[j]))
end
function demo2(...)
local vars7 = 0
for k, v in pairs{...} do
vars7 = vars7 + v
end
return vars7
end
io.write("vars7 : ", demo2(1,2,3,4,5,6), "\n")
vars8 = function(x) return x * 2 end
print(vars8(4))
function demo3()
local i = 0
return function()
i = i + 1
return i
end
end
vars9 = demo3()
print(vars9())
print(vars9())
for p=2,20 do
for q=2,20 do
for r=2,20 do
if r^1 + q^3 == p^4 then
print('Welcome To My Domain thanks for give the inputs for executing the loop statemnet using continue concept:', r, q, p)
print('Please continue your inputs p...')
goto continue
end
end end ::continue:: end
Output:
In above example we used functions and loops for to evaluate the user input values based on the requirements. We can pass the input as strings, numbers on the script. We also use for loop for to iterate the values it will be continued further by using goto continue statement.
Example #2
Code:
vars = coroutine.create(function()
for i = 2, 20, 3 do
print(i)
print(coroutine.status(vars))
if i == 7 then coroutine.yield() end
end end)
print(coroutine.status(vars))
coroutine.resume(vars)
print(coroutine.status(vars))
vars1 = coroutine.create(function()
for i = 201, 210, 2 do
print(i)
end end)
for a=1,5 do
for b=1,5 do
for c=1,5 do
if a^1 + b^2 == c^3 then
print('Welcome To My Domain thanks for give the inputs for executing the loop statemnet using continue concept:', a, b, c)
print('Please continue your inputs p...')
goto continue
end
end end ::continue:: end
coroutine.resume(vars1)
coroutine.resume(vars)
Output:
The above example we used coroutines concept for continue the user process until its goes to end. With the help of for loops the tasks process is repeated until the condition is fulfilled on the requirement.
Example #3
Code:
Example = {height = 1, weight = 1, name = "Welcome To My Domain", city = "Tiruppur"}
function Example:new (height, weight, name, city)
setmetatable({}, Example)
self.height = height
self.weight = weight
self.name = name
self.city = city
return self
end
function Example:toString()
vars = string.format("%s weighs %.3f lbs, is %.3f in tall and says %s", self.name, self.weight, self.height, self.city)
return vars
end
vars1 = Example:new(124, 567, "Welcome User", "Chennai")
print(vars1.weight)
print(vars1:toString())
Example1 = Example:new()
function Example1:new (height, weight, name, city, Country)
setmetatable({}, Example1)
self.height = height
self.weight = weight
self.name = name
self.city = city
self.Country = Country
return self
end
function Example1:toString()
vars2 = string.format("%s weighs %.3f lbs, is %.3f in tall, says %s and loves %s", self.name, self.weight, self.height, self.city, self.Country)
return vars2
end
for x=1,6 do
for y=1,6 do
for z=1,6 do
if x^1 + y^2 == z^3 then
print('Welcome To My Domain thanks for give the inputs for executing the loop statemnet using continue concept:', x, y, z)
print('Please continue your inputs p...')
goto continue
end
end end ::continue:: end
vars3 = Example1:new(124, 567, "Thanks user", "Have a Nice Day", "Chennai")
print(vars3:toString())
Output:
In final example we used basic functionality of the lua script that is we can calculate the height and weight of the objects. It will be iterate the input values like similar to the previous example and it continues until the loop is exit the input conditions.
Conclusion
In Lua script we used basic conditional statements and loops for checking and validating the user inputs. Like that continue is one of the concept for executing the script on further steps and it is another way for evaluating and exist the looping statements. With the help of goto continue the script will continue for their tasks.
Recommended Articles
We hope that this EDUCBA information on “Lua continue” was beneficial to you. You can view EDUCBA’s recommended articles for more information.