in reply to Re^4: Control Structures
in thread Control Structures
your example structure still doesn't behave like switch/case in CYes, it does implement fall-through. Try it. The example program I gave demonstrated it. See the two lines of output for needs_slight_cleaning? It doesn't have to match 'good value' (how could it?) to get that second output line.
If I didn't want to implement fall-through, I would have just had a bunch of ifs. If it doesn't encounter last, it's going to keep calling $case->(), which will short-circuit true if it has previously matched (that is the purpose of the $matched variable in the closure). last acts like break.Checking testing...Default Checking needs_slight_cleaning...Clean up values Whatever you need Checking good value...Whatever you need Checking totally unrelated...Something else
Update: To stack up things like you did here, just have a series of calls to $case-() as separate statements (or you could join them up with ors), and follow the last one with && whatever.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: Control Structures
by jhourcle (Prior) on May 10, 2005 at 15:38 UTC | |
by Roy Johnson (Monsignor) on May 10, 2005 at 16:00 UTC |