If else statement help
-
I am using if/else statements to show and hide some elements in my UI but I'm hoping I can streamline it a bit.
I have got the basic if/else statements to work eg
If condition 1 is true do thing AI am unsure of the correct syntax for multiple things to happen if the condition is met.
For example:
If condition 1 is true do thing A and thing BCan somebody point me in the right direction please?
Thanks in advance
-
@rzrsharpeprod Multiple lines need to be in curly braces
if (condition) { doThingA(); doThingB(); } else { doThingC(); doThingD(); }
-
If it's more than a three you might want to use a switch statement.
-
@iamlamprey said in If else statement help:
@rzrsharpeprod Multiple lines need to be in curly braces
if (condition) { doThingA(); doThingB(); } else { doThingC(); doThingD(); }
Thankyou, that makes sense and seems straightforward. I'll give that a go, thanks again
-
@d-healey said in If else statement help:
If it's more than a three you might want to use a switch statement.
Thanks David. Is that for cleaner code and more efficient processing purposes?
-
@rzrsharpeprod It's cleaner code. Probably doesn't make a difference to efficiency in terms of resource usage, but it's more efficient from the point of view of writing and maintaining your code, and readability.
Also depending on what exactly you're trying to do there might be other ways to write it that are more efficient.