It seems like you can do something like this:
switch ($foo) {
case 'a':
if (do_a()) echo "a was done";
else print_menu(); // changes here
break;
case 'b':
if (do_b()) echo "b was done";
else print_menu(); // changes here
break;
case 'menu':
print_menu();
Regardless of how many break statements you take away (even
if only 1), case statements appear to be ignored after the
first match is made. I need a way to make the switch statement
continue evaluating case-matches, even after the first case
match is made. Further, it should allow one case segment
Well, you don't have to take away all the "break;". :)
For example, only here:
> switch ($foo) {
>case 'step2':
>do_step2();
>if ($error) $foo='step1'; //repeat step1
>break;
- E
>
>
>If you don't break, it continues to execute all the code until
>the end of the switch, ignorin
If you don't break, it continues to execute all the code until
the end of the switch, ignoring any subsequent case
statements.
In my example, eliminating the break after step2 would
cause execution of do_step1(), but also do_something_else(),
which is not desired.
--- "@ Edwin" <[EMAIL PROTECTE
Actually, you can--just don't "break;".
Try it.
- E
>
>I'd like to be able to modify the switch variable inside a case
>statement, like this:
>
>switch ($foo) {
> case 'step2':
> do_step2();
> if ($error) $foo='step1'; //repeat step1
> break;
>
> case 'step1':
> do_step1();
>
I'd like to be able to modify the switch variable inside a case
statement, like this:
switch ($foo) {
case 'step2':
do_step2();
if ($error) $foo='step1'; //repeat step1
break;
case 'step1':
do_step1();
break;
case 'a_third_thing':
do_something_else();
break;
}
Can y
6 matches
Mail list logo