php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8768 'continue' inside of 'switch' statement acts like 'break' instead of 'continue'
Submitted: 2001-01-17 16:50 UTC Modified: 2001-03-06 08:03 UTC
From: godai at neomueller dot org Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: godai at neomueller dot org
New email:
PHP Version: OS:

 

 [2001-01-17 16:50 UTC] godai at neomueller dot org
When a continue is used inside of a switch statement (inside a loop), it does not jump to the top of the next
loop iteration, but instead jumps out of the switch statement and proceeds to execute the code following the
switch.  The following code snippet should give a good example:

<?php
 for( $i = 0; $i < 10; $i++ ) {
    
      switch( $i ) {
        case 5:
          continue;
        default:
          $garbage = 0; // do something unimportant
      }
      
      echo "$i<BR>";
      
    }
?>

The output *should* be the numbers 0 to 4 & 6 to 9 listed down the screen, skipping 5. Instead, 5 appears
in the list making it a complete 0 to 9.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-06 08:03 UTC] stas@php.net
switch is a looping structure in PHP, just like for, but
one-time. Use "continue 2;" if you want to continue the
outer loop. 
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 20:01:29 2024 UTC