If and Elseif are control structures designed to operate the flow of commands.

If you have one value (%a) and there are multiple possible values it could be, and you want different actions to happen if it's different values, you use if-elseif-elseif to do the checking.

If you are checking completely different variables for completely diferent things, you'd use separate if statements.

So using your example, take a look at this code:

  1. if (%a == a) && (%b == b) && (%c == c) { blah }
  2. elseif (%a != a) && (%b == b) && (%c == c) { blah }
  3. elseif (%a == a) && (%b != b) && (%c == c) { blah }
  4. elseif (%a == a) && (%b == b) && (%c != c) { blah }
  5. else { blah }
With that code in mind, lets consider the following scenareos:
  • /var %a = a, %b = b, %c = c -> This will hit 1
  • /var %a = b, %b = b, %c = c -> This will hit 2
  • /var %a = a, %b = a, %c = c -> This will hit 3
  • /var %a = a, %b = b, %c = a -> This will hit 4
  • /var %a = b, %b = c, %c = c -> This will be caught by 5
5 will catch all other possible variations of the variables not being one of the listed value sets.

Now, you were wondering about speed. There's two considerations.

if you just used 'if' for all 5 lines, it would be slower for this example as it would check all 4 if's every time though, and wouldn't skip out of the structure if it hit earlier.

As with genius_at_work's earlier example, the red lines would never get evaluated as it matched an earlier line. This is the point of an if-elseif-else structure.

How about a real world example? This is from my remotes:

Code:
ON *:CONNECT: {
  if ($istok(rizon irchighway chatspike darkernet, $network, 32) && ($me == $mnick)) {
    .msg nickserv identify <password>
    if ($network == rizon) {
      .mode $me -x
      .timer 1 10 .join -n #chan1,#chan2,#chan3
      .timer 1 11 .join -n #chan4,#chan5,#chan6
      join -n #chan7,#chan8,#chan9
    }
    elseif ($network == irchighway) {
      .timer 1 5 .mode $me -r
      .join -n #chan1,#chan2,#chan3
      .timer 1 30 .join -n #chan4,#chan5,#chan6
    }
    elseif ($network == chatspike) {
      .join -n #chan1
    }
  }
}

It should be fairly straight forward what this means.