Jump to content

jump from one "case" to another?


Hyaku_

Recommended Posts

That's not true.

Try this example:
[code]<?php
if (isset($_GET['v']))
switch($_GET['v']) {
case '0':
echo 'zero<br>';
case '1':
echo 'one<br>';
case '2':
echo 'two<br>';
case '3':
echo 'three<br>';
default:
echo 'default<br>';
}
?>[/code]

Or in action at http://www.rbnsn.com/phpfreaks/case_test.php?v=0

Ken
Well, this doesn't work?

[code]#!/usr/bin/php
<?php

    $a = 10;
    $v = 1;

    switch ($v) {
        case 1:
            if ($a == 10) {
                break;
            } 
        break;
        case 2:
            echo "this is two";
        break;
    } 

?>
[/code]
It's not displaying anything since $a is 10 in your example, change it to something else:
[code]<?php
    $a = 20;
    $v = 1;

    switch ($v) {
        case 1:
            if ($a == 10) {
                break;
            } 
        case 2:
            echo "this is two";
        break;
    } 

?>[/code]

Ken
Well, I was trying to acomplish this:
[code]

switch($mode){
      case "read_pm":
                  if(id_of_pm_doesn't_exist_in_the_db){
                            don't_display_error_just_jump_to_case_list_pm;
                  }
      break;

    case "list_pm":
              list_all_private_messages();
    break;

}[/code]
I know how it can be done in different way, but I just thought if it would be posible to go to case "list_pm" on error, it would be preatty clean, but I guess I could use [i]goto[/i], but I don't want to use it.. Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.