else if vs if

This is a discussion on else if vs if within the C++ Programming forums, part of the General Programming Boards category; what's the difference/purpose of using a tree of else if(s) against a series of if(s)?...

  1. #1
    Set Apart -- jrahhali's Avatar
    Join Date
    Nov 2002
    Posts
    256

    else if vs if

    what's the difference/purpose of using a tree of else if(s) against a series of if(s)?

  2. #2
    Me -=SoKrA=-'s Avatar
    Join Date
    Oct 2002
    Location
    Europe
    Posts
    448
    Speed. A series of ifs will all be checked, but if, for example the first if condition is met, the rest in the if-else block will not be tested. This only works if the conditions are mutually exclusive, but if several can be met at once, you'd need to use a series of ifs, or a series of ef-else blocks.
    SoKrA-BTS "Judge not the program I made, but the one I've yet to code"
    I say what I say, I mean what I mean.
    IDE: emacs + make + gcc and proud of it.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21