ID:               17556
 Updated by:       [EMAIL PROTECTED]
 Reported By:      [EMAIL PROTECTED]
 Status:           Open
-Bug Type:         Scripting Engine problem
+Bug Type:         Documentation problem
 Operating System: All
 PHP Version:      4.2.1
 New Comment:

Looks like docs problem, not Engine problem.


Previous Comments:
------------------------------------------------------------------------

[2002-07-31 18:53:25] [EMAIL PROTECTED]

reclassified.


------------------------------------------------------------------------

[2002-07-30 04:12:11] [EMAIL PROTECTED]

Here are two examples:
<?php

$counter = 0;
while ($counter<20){
        switch ($counter){
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                        $counter++;
                break;
                default:
                        $counter+=2;
                        continue;
                
        }// swhitch
        echo 'FUBAR'."[$counter]\n";    
}//while

?>
<?php
$counter = 0;
while ($counter<20){
        switch ($counter){
                case 0:
                case 1:
                case 2:
                case 3:
                case 4:
                case 5:
                case 6:
                case 7:
                case 8:
                case 9:
                        $counter++;
                break;
                default:
                        $counter+=2;
                        continue(2);
        }// switch
        echo 'FUBAR'."[$counter]\n";    
}// while
?>
The intention is to show that there is no note in the docs for that
when programmer wants to go to the next iteration of the loop that is
shell to the switch() he/she must use continue(2); not continue;. This
is because in switch()-es continue; is equivalent to break;
In general if programmer want to skip the rest of the n-th loop
(counted from the most inner to most outter) he must use continue(n+1);
and not contunie(n);

If there is something hard to get (beacuse of my english) please
contact me and I will explain.
Regards,
Andrey Hristov

------------------------------------------------------------------------

[2002-07-29 16:47:36] [EMAIL PROTECTED]

With respect to what you "wanted to say", your second example is not
what you explained in your original report. Be more careful with your
wording or include an example that clarifies your report. If you
re-read your first report there is *no mention at all* of the case
where switch is inside a loop (while, for, etc.)





Also, your logic does not seem too clear to me in your example. What is
the *exact* intended effect?, perhaps that the "continue" goes to the
top of the while loop  even though it is *not* in the current scope of
that block but in the switch block, that will be an odd behaviour
indeed. 





If you can be:





(a) more precise w/ respect to the execution flow, 





(b) provide some examples of other scripting languages where the switch
supports a continue that behaves like you are mentioning here, 





(c) explain why such a construct is desirable instead of the more logic
one of doing a break in the switch block and perfoming the conditional
comparison outside the switch block, so you are not dependent on
side-effects (which can be tricky to debug later on)





Then there will be a good change to reopening this bug. Will wait for
your feedback, but will not reclassify this out of "Bogus" for the time
being.




------------------------------------------------------------------------

[2002-07-29 10:11:54] [EMAIL PROTECTED]

I think that Mr Jesus Catagnetto misunsterstood what I am talking
about. IMO the bug must be reopened.

I just wanted to say that
while (some){
 switch ($foo){
   case 'bar':
    if (some_reason) continue;//ie next iteration, but no, it will
increment counter after the switch. Must be continue(2);
   break;
   case 'boo':
    //
   break;
   default:
   break;
 }
echo $counter++;
}

------------------------------------------------------------------------

[2002-06-01 17:02:20] [EMAIL PROTECTED]

Ehem, the documentation for "switch" explicitly says:

"... The switch statement is similar to a series of IF statements on
the same expression ..."

And I do not know of any language that uses a series of if statements
as a loop construct (that is why for, while and do ... while are
there). If you know of one, I will be interesting to check it out to
see how that can be done.

Also, nowhere there is mentioned that "continue" can be used to loop in
a non-looping construct (e.g. if), and if you read again the the
description of "continue" it says:

"continue is used within looping structures to skip the rest of the
current loop iteration and continue executio at the beginning of the
next iteration"

thus if you use that in a context where there is no loop, it just gets
out of scope.

This is (or should) something learned in basics of programming book,
article, etc.


------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/17556

-- 
Edit this bug report at http://bugs.php.net/?id=17556&edit=1


-- 
PHP Documentation Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to