Req #32059 [Csd->Bgs]: ranges in switch

From: Date: Mon, 15 Nov 2010 19:41:00 +0000
Subject: Req #32059 [Csd->Bgs]: ranges in switch
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-156062@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=32059&edit=1

 ID:                 32059
 Updated by:         pajoye@php.net
 Reported by:        scooley at apple dot com
 Summary:            ranges in switch
-Status:             Closed
+Status:             Bogus
 Type:               Feature/Change Request
 Package:            *General Issues
 Operating System:   mac os x
 PHP Version:        5.0.3
 Block user comment: N

 New Comment:

not a bug > bogus


Previous Comments:
------------------------------------------------------------------------
[2010-11-15 19:15:41] scooley at apple dot com

Hey, so it's been pointed out to me that this is possible already.


switch($var)
	{

	case ($var <=9):
		{
		do_this();
		break;
		}

	case ($var >= 10) && ($var <= 100) :
		{
		do_something();
		break;
		}

	}

Basically, the cases just need to evaluate to true or false in order for
the code within to run, so you can do comparisons and ranges; you just
need to form them correctly.

------------------------------------------------------------------------
[2010-11-15 14:44:53] scratch65535 at att dot net

I too think it would be very convenient to allow a range as a case,
e.g.

switch( $somevar )
{
    case 1..5 :
        // code & break
    case 6..23 : 
        // code & break
    // etc
}

(I also think it'd be very convenient if bugzilla didn't claim
"incorrect captcha" when the problem is "i can't set a cookie")

------------------------------------------------------------------------
[2005-02-21 23:55:17] scooley at apple dot com

Description:
------------
why not some behavior like this?

...
switch($var)
	{
	case <= 9:
		{
		echo "less than ten";
		break;
		}
	case 10:
		{
		echo "ten exactly";
		break;
		}
	case >10 <> <15:
		{
		echo “a range of values? why not?";
		break;
		}
	case >= 15:
		{
		echo “greater than or equal to fifteen";
		break;
		}
	default:
		{
		echo “what am I not thinking of here?”
		break;
		}
	}
…



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



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


Thread (1 message)

  • pajoye@php.net
  • Unknown Message
    • pajoye@php.net
« previous php.bugs (#156062) next »