Re: Syntax
| From: | B. Aerts | Date: | Wed, 23 Sep 2015 11:24:42 +0000 |
| Subject: | Re: Syntax | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-325134@lists.php.net to get a copy of this message | ||
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 ?