What do put in an if else command if i want the "if" to just make the script continue to run? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What do put in an if else command if i want the "if" to just make the script continue to run?

9th May 2017, 12:27 PM
Ben Galbraith
3 Answers
+ 9
You can always leave your if statements empty. I recommend you to alter your if condition though, to run when the script shouldn't continue as usual. E.g. Instead of var i = 1; if (i == 0) {} else { // something } try doing if (i != 0) { // something }
9th May 2017, 12:36 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
The 'if/else' statement is linked in one way only: you cannot use 'else' alone ( as it's non sense ), but it's allowed to use only the 'if' ^^ Personnally, rather than testing the condition and put a long code in the 'if' body, I prefer test the inverse condition, and exit from here... so next code is never executed if the ( inverse ) condition is true, and 'else' is implicite rather than eplicit: if (myCondition==false) { return; } /* code to execute if myCondition == true */
9th May 2017, 1:06 PM
visph
visph - avatar
0
You could always put a 'not' in front of your comparison. Something like: if !(x == y) { // code that used to be in the else statement }
9th May 2017, 1:14 PM
botheredbybees
botheredbybees - avatar