Hi, I’m developer. just a quick question, does 2nd conditions skip if there’s [or] and 1st conditions is true?
Just like:
if true or false then
print("foo bar")
end
This will print foo bar of course because 1st conditions is true, but does they skip [false] conditions? (2nd)
I’m sorry that this is basic questsion and my curious thinkings and not following to template.
thank you!
Well the answer to this question is relatively straight forward.
When using the “or” statement you are simply checking for one of the parameters to be true.
So when you put “true or false” the first parameter is true therefore running that block of code however, if you put false or true the block of code will still run due to the second parameter being true. Hope that helps!
Though this isn’t the case for C# (and probably C and C++)
using System;
public class Program
{
public static void Main()
{
Console.WriteLine(true || (true + 1)); //
Compilation error (line 7, col 30): Operator '+' cannot be applied to operands of type 'bool' and 'int'
}
}
This also apply to falsy (false and nil in Lua, 0, ''false, None, and many more in Python, undefined, +0, NaN, -0, 0n, "", null in Javascript) values and the and statement
print(false and (1 + nil)) --> false
print(nil and (1 + nil)) --> nil
print(true and (1 + nil)) --> Errors