This is what i meant:
variable = 1
anothervariable = 2
if variable == 1 then
if anothervariable == 2 then
--do stuff
What's the different with:
if variable == 1 and anothervariable == 2 then
--do stuff
This is what i meant:
variable = 1
anothervariable = 2
if variable == 1 then
if anothervariable == 2 then
--do stuff
What's the different with:
if variable == 1 and anothervariable == 2 then
--do stuff
An if statment will create a new scope. Depending upon your code additional logic may be required in some cases.
Example:-
for i=1, 10 do
if i % 2 == 0 then
if i == 10 then
-- this is a new scope
print('This is the last number')
end
-- print all even numbers
print(i)
end
end
Combining the logic
for i=1, 10 do
if i % 2 == 0 and i == 10 then
print('This is the last number')
print(i)
end
end
As you can see the results of this code are not the same due to the different logic being executed.
"then if' and 'and' in an if statement" are not comparable as they do different tasks and change the logic of the code.
There's probably no difference, we just use the and statement to make our code look more efficient and it can probably reduce lag in your game.
This discussion is preserved as it was. New answers, comments, and votes are closed.
2 comments
Yes!
Thank you!