Re: switch labels in sub-blocks

From: Date: Fri, 28 May 2004 21:05:08 +0000
Subject: Re: switch labels in sub-blocks
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-10165@lists.php.net to get a copy of this message
Ard Biesheuvel wrote:
Hi all, is there a specific reason why nested blocks in switch statements are not supported ? It can be very useful if you want to jump into the middle of the first iteration of a loop (like fetching rows from a result set where the first row might or might not be already present) Eg. switch ($i) { case 0:
    do {
        // iteration
default:
    } while ( /* some condition */ );
} It looks like using "goto" to me. Messy.
That's probably the reason it is not allowed. Or maybe other people like myself failed to understand how it is really useful. Real example from you would help here. Anyway, are you really sure you want to do that? #### (what it would be with "goto") #### $i=7; $t=0; switch($i) {
    case 0:
        do {
            echo "($t)";
            label1:
            echo "[$t]";
        } while(++$t<3);
    default:
        goto label1;
} #### Just my 2 agoras...

« previous php.internals (#10165) next »