Updated April 19, 2023
Introduction to Lua not equal
In Lua script not equal is defined as one of the operator which is helpful for to validate the user input conditions in both front and back end “~=” is the operator symbol for checking the user input conditions that is if the value of the two operands are satisfied the user requirements and comparing it them for performing the application workflow to the next step with the help of some conditional loop statements this operator task is performed both automatically and manually in the script and these operators are returning only the boolean conditions like true or false.
Syntax:
In basically Lua Script has default keywords, variables, and methods for performing the operations in both system and web-based applications. Likewise not equal is one of the relational operators for checking the user input data in both front and back end for validation purpose. By using some conditional statements it will be applicable for a programmer perspective.
variable name1 =input values
variable name2 =input values
conditional statements(if,do,for,while etc) (variable name1 ~= variable name2)
then// keyword
-----some script code logics it depends upon the user requirements---
In above code is one of the syntaxes for using and validating the not equal(~=) operator in the script. We may use other relational operators with this operator which depends upon the programmer’s thinks and requirements based upon the project.
How not equal operator works in Lua?
Generally, Lua script based on some types of operators which used upon the script and it requires the project and application for both authenticating and non-authenticating purpose. Like that, not equal(~=) is one of the relational operators and it returns only the boolean set of statements like true and false. If the two operands (user inputs) are satisfied the user conditions, it returns true, or else it will return false statements. These types of operators are used for testing purpose in both quality and quantity items and it is mainly depending upon the negation of equality that is it seems to be the opposite of the equality conditions. So that we can use it for other relational operators for any type of values which is going to be a comparison of the two segments. Suppose if the two operands values are different data types the Lua script also considers it for a different set of values otherwise it compares the values according to their data types. Basically, the “nil” is the value for comparing or equally for themselves in the script. Using this operator, we can compare other types also like tables, functions used by the script it may be either default or user-defined functions. With the help of their instances, the operators are sued and applied it for another type of variables.
Example #1
Code:
vars = {}
first = 3
second = 3
for x=2,first do
for y=2,second do
vars[x*second +y] = x*y
end
end
for x=2,first do
for y=2,second do
print(vars[x*second +y])
end
end
local p = "Second"
if p ~= "Second" then
print("welcome to My Domain Thanks for validating your inputs to the specific outputs")
else
print("Thanks for providing your inputs to the script please try again")
end
Sample Output:
In the above example, we used not equal(~=) operator for validating the inputs. Here we used for loops to iterate the values and by using the expression “vars[x*second +y]” it can calculate the values and print them on the user output console.
Example #2
Code:
demo = {"First", "Second", "Third", "Four", "Five",
"Six", "Seven", "Eigth", "Nine", "Ten", "Eleven",
"Twelve"}
for p, q in pairs(demo) do
io.write(q, " ")
end
print()
x = {}
for j = 1, 20 do
x[j] = j
end
io.write("Welcome To My Domain Your Firt input is : ", x[1], "\n")
io.write("Welcome To My Domain Your Second input is : ", #x, "\n")
table.insert(x, 1, 0)
print(table.concat(x, ","))
table.remove(x, 1)
print(table.concat(x, ", "))
table.sort(x, function(l,m) return l>m end)
print(table.concat(x, ", "))
y = {}
for j = 1, 15 do
y[j] = {}
for k = 0, 9 do
y[j][k] = tostring(j) .. tostring(k)
end
end
io.write("Welcome User your second input table is ", y[2][8], "\n")
for j = 3, 9 do
for k = 3, 9 do
io.write(y[j][k], " : ")
end
print()
end
if demo ~= "Second" then
print("welcome to My Domain Thanks for validating your inputs to the specific outputs")
else
print("Thanks for providing your inputs to the script please try again")
end
Sample Output:
In the second example, we can create the tables for storing the data in rows and column formats. By using default methods of the table packages we can sort and remove the table data. By using not equal operators we can validate the user inputs on the script. The loop will execute only for the given limit of data that is 1 to 15, 1 to 20, etc. We can also reverse the input numbers and print the output as 3 to 9 as the last for loop it will iterate the values for starting value is 3 and the ending value is 9.
Example #3
Code:
vars = coroutine.create(function()
for j= 2, 20, 3 do
print(j)
print(coroutine.status(vars))
if i == 5 then coroutine.yield() end
end end)
print(coroutine.status(vars))
coroutine.resume(vars)
print(coroutine.status(vars))
vars1 = coroutine.create(function()
for k = 200, 300, 3 do
print(k)
end end)
if k ~= 201 then
print("welcome to My Domain Thanks for validating your inputs to the specific outputs")
else
print("Thanks for providing your inputs to the script please try again")
end
coroutine.resume(vars1)
coroutine.resume(vars)
Sample Output:
In the final example, we used coroutine the default method for the Lua script. It uses some activity like processing the asymmetric calls and it is used to suspend the activity whenever we need to use the yield method. The process will continue till the execution process complete from the coroutine package.
Conclusion
The Lua users will use some lightweight applications like game developers, other web-based applications, image processing techniques. These applications are more attractive and user-friendly in nature in the users, so when we create the applications we can use some operators, keywords, and functions for creating the application based on the user requirements.
Recommended Articles
We hope that this EDUCBA information on “Lua not equal” was beneficial to you. You can view EDUCBA’s recommended articles for more information.