Re: Syntax

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 23/09/15 09:33, Karl DeSaulniers wrote:


And on a side note, what is up with the default on a switch statement?
That thing always fires no matter what, I essentially never use it because of this.


The default should fire if none of the preceding tests pass.

Of course, if the last test doesn't hold a 'break', the default will be executed too, as any test that doesn't terminate with a break.

switch(condition)
{
   test 'A' :
      // code for condition 'A'
      break ;
   test 'B' :
      // code for condition 'B'
      // *** mind the missing 'break ;' ***
   default :
      // code for condition 'C'
}

If condition equals 'B', this will run both the code for 'B' and the default code.
If condition equals 'C', it will run the default code only.

Sure you haven't omitted a break before your default-always-firing statement ?




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux