Reply to Re: Switch isset and $_get

Your name:

Reply:


Posted by Pedro Graca on 10/22/06 19:17

Juliette wrote:
> Contrary to the (non-)problem highlighted by another poster, having
> several expressions here that could be true, is not a problem.

I apologize for not checking before posting (I was thinking C, where it
is illegal to have different cases with the same value).

Thank you for catching my error and calling attention to it.

> Switch will execute the first case it comes across which is valid. If
> that case is closed by 'break;', it will then terminate the switch, if
> the case is closed by 'continue;' it will continue to evaluate the other
> options too.

`continue` will behave exactly like break.

When there is no match for the case expressions and there are several
`default` cases (illegal in C too), the one chosen seems to be the last
and not, as I expected, the first.

> In other words choosing the order of your cases is very important if you
> use this syntax when several cases can be true.


<?php
for ($i=0; $i<3; ++$i) {
switch ($i) {
case 1: echo "first case 1\n"; break;
case 2: echo "first case 2\n"; continue;
default: echo "first default\n"; continue;
case 1: echo "second case 1\n"; continue;
case 2: echo "second case 2\n"; break;
default: echo "second default\n"; break;
}
}
?>


--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация