Just wondering, but assuming you had maybe 10 different values to compare to X, would it be better to write one giant long if condition, or a for loop with an if-statement that returns true if x == value, and then false if the for loop finishes without returning true?
Long If Condition or For Loop with If Condition?
463 Views Asked by Jacob Macallan At
3
The long if statement is going to be hard to read for humans and space consuming. It will be slightly faster however than the for loop, but that should't bother you.
A better way would be to make the for loop in a separate function that returns boolean value or storing the comparison values in an array and checking something like: