21

Else if, elif, elseif, if else garrgghj. I can never remember what it is in whatever language I happen to use...

Comments
  • 6
    If you use a text editor (not notepad) / IDE, a font color change may tell which one is the correct syntax.
  • 1
    Else if should work in most languages. [Based on my experience, I may be wrong].
  • 2
    you could always do

    If(condition) {

    } else {
    if(condition) {

    }
    }

    // ¯\_(ツ)_/¯
  • 0
  • 0
    condition && (f1() || true) || (f2() || true)

    I think that works in most languages... But probably easier to just remember which if/else variant to use.
  • 0
    If ...
    Statements...
    fi

    😉
  • 0
    Totally feel you. We all need to be united under one syntactic language and one benevolent, supreme leader - Kim Jong Un!
  • 3
    I want to know what ass hat in the Visual Basic team said "you know, we need to add 'then' to the end of each if statement"
  • 1
    There's no functional difference between `elseif` and `else if`
  • 0
    @Ashkin yes there is, ex in Java if you type "else if" it will compare two conditions if an if or else if statement's condition is false, but of you type elseif it won't compile
  • 1
    @calmyourtities
    Not all languages have an `elseif` -- and with good reason: it's pointless.

    if (condition) {
    ...
    } else if (condition) {
    ...
    }

    So if the first condition is false, it compares the second condition. How is this different than `elseif`? Spoiler: it isn't!
  • 1
    @Ashkin many people argue that using any form of "else" is an antipattern, because the if should contain the least likely path with an early return to the caller, and methods should be short and modular.
  • 1
    @bittersweet That works wonderfully for guards. (Kind of not the point though!)
Add Comment