Re: [PHP] alter switch variable inside case?

2002-08-31 Thread @ Edwin
Actually, you can--just don't "break;".

Try it.

- E


I'd like to be able to modify the switch variable inside a case
statement, like this:

switch ($foo) {
   case 'step2':
 do_step2();
 if ($error) $foo='step1'; //repeat step1
   break;

   case 'step1':
 do_step1();
   break;

   case 'a_third_thing':
 do_something_else();
   break;
}

Can you modify the variable ($foo) inside a case statement and
have it evaluated for subsequent 'case's like this? If not, I
will have to revert to a series of if statements, in which this can
be done:

if ($foo=='step2') {
   do_step2();
   if ($error) $foo='step1';
}
if ($foo=='step1') {
   do_step1();
}
etc.

Switch-case seems cleaner, and I'd prefer to stick with it.

__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

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





_
$B$+$o$$$/$FL{2w$J%$%i%9%HK~:\(B MSN $B%-%c%i%/%?!<(B http://character.msn.co.jp/


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


Re: [PHP] alter switch variable inside case?

2002-08-31 Thread Joe Janitor


If you don't break, it continues to execute all the code until
the end of the switch, ignoring any subsequent case
statements.

In my example, eliminating the break after step2 would
cause execution of do_step1(), but also do_something_else(),
which is not desired.

--- @ Edwin [EMAIL PROTECTED] wrote:
 Actually, you can--just don't break;.
 
 Try it.
 
 - E
 
 
 I'd like to be able to modify the switch variable inside a case
 statement, like this:
 
 switch ($foo) {
case 'step2':
  do_step2();
  if ($error) $foo='step1'; //repeat step1
break;
 
case 'step1':
  do_step1();
break;
 
case 'a_third_thing':
  do_something_else();
break;
 }
 
 Can you modify the variable ($foo) inside a case statement and
 have it evaluated for subsequent 'case's like this? If not, I
 will have to revert to a series of if statements, in which this can
 be done:
 
 if ($foo=='step2') {
do_step2();
if ($error) $foo='step1';
 }
 if ($foo=='step1') {
do_step1();
 }
 etc.
 
 Switch-case seems cleaner, and I'd prefer to stick with it.
 
 __
 Do You Yahoo!?
 Yahoo! Finance - Get real-time stock quotes
 http://finance.yahoo.com
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 
 _
 ¤«¤ï¤¤¤¯¤ÆÌû²÷¤Ê¥¤¥é¥¹¥ÈËþºÜ MSN ¥­¥ã¥é¥¯¥¿¡¼ http://character.msn.co.jp/
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

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




Re: [PHP] alter switch variable inside case?

2002-08-31 Thread @ Edwin
Well, you don't have to take away all the "break;". :)

For example, only here:

  switch ($foo) {
case 'step2':
do_step2();
if ($error) $foo='step1'; //repeat step1
break;

- E



If you don't break, it continues to execute all the code until
the end of the switch, ignoring any subsequent case
statements.

In my example, eliminating the break after step2 would
cause execution of do_step1(), but also do_something_else(),
which is not desired.

--- "@ Edwin" [EMAIL PROTECTED] wrote:
  Actually, you can--just don't "break;".
 
  Try it.
 
  - E
 
  
  I'd like to be able to modify the switch variable inside a case
  statement, like this:
  
  switch ($foo) {
 case 'step2':
   do_step2();
   if ($error) $foo='step1'; //repeat step1
 break;
  
 case 'step1':
   do_step1();
 break;
  
 case 'a_third_thing':
   do_something_else();
 break;
  }
  
  Can you modify the variable ($foo) inside a case statement and
  have it evaluated for subsequent 'case's like this? If not, I
  will have to revert to a series of if statements, in which this can
  be done:
  
  if ($foo=='step2') {
 do_step2();
 if ($error) $foo='step1';
  }
  if ($foo=='step1') {
 do_step1();
  }
  etc.
  
  Switch-case seems cleaner, and I'd prefer to stick with it.
  
  __
  Do You Yahoo!?
  Yahoo! Finance - Get real-time stock quotes
  http://finance.yahoo.com
  
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
  
 
 
 
 
  _
  $B!"%)!"!&!"!"%C!"%K%U{v(B#58759;$B%O!&!"!'%1!&%M%R(B#63730;$B%3%o(B MSN 
$B!&%e!'r'%C!&%=!#%7(B 
http://character.msn.co.jp/
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

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




_
$B2q0wEPO?$OL5NA!&=<

Re: [PHP] alter switch variable inside case?

2002-08-31 Thread Joe Janitor

Regardless of how many break statements you take away (even
if only 1), case statements appear to be ignored after the
first match is made. I need a way to make the switch statement
continue evaluating case-matches, even after the first case
match is made. Further, it should allow one case segment to
alter the switch variable and have such alteration taken 
into account for subsequent matches.

Here's a more illustrative example of my situation:

switch ($foo) {
  case 'a':
if (do_a()) echo a was done;
else $foo='menu';
  break;

  case 'b':
if (do_b()) echo b was done;
else $foo='menu';
  break;

  case 'menu':
print_menu();
  break;

  case 'logout':
do_logout();
  break;
}

that code will not print_menu if do_a fails, since
it exits the switch statement upon seeing a break.

if I remove the break after do_a, it will execute
do_a and do_b -- bad. what we really want is for it
to execute do_a and if do_a returns false, print_menu.

Joe

--- @ Edwin [EMAIL PROTECTED] wrote:
 Well, you don't have to take away all the break;. :)
 
 For example, only here:
 
   switch ($foo) {
 case 'step2':
 do_step2();
 if ($error) $foo='step1'; //repeat step1
 break;
 
 - E
 
 
 
 If you don't break, it continues to execute all the code until
 the end of the switch, ignoring any subsequent case
 statements.
 
 In my example, eliminating the break after step2 would
 cause execution of do_step1(), but also do_something_else(),
 which is not desired.
 
 --- @ Edwin [EMAIL PROTECTED] wrote:
   Actually, you can--just don't break;.
  
   Try it.
  
   - E
  
   
   I'd like to be able to modify the switch variable inside a case
   statement, like this:
   
   switch ($foo) {
  case 'step2':
do_step2();
if ($error) $foo='step1'; //repeat step1
  break;
   
  case 'step1':
do_step1();
  break;
   
  case 'a_third_thing':
do_something_else();
  break;
   }
   
   Can you modify the variable ($foo) inside a case statement and
   have it evaluated for subsequent 'case's like this? If not, I
   will have to revert to a series of if statements, in which this can
   be done:
   
   if ($foo=='step2') {
  do_step2();
  if ($error) $foo='step1';
   }
   if ($foo=='step1') {
  do_step1();
   }
   etc.
   
   Switch-case seems cleaner, and I'd prefer to stick with it.
   
   __
   Do You Yahoo!?
   Yahoo! Finance - Get real-time stock quotes
   http://finance.yahoo.com
   
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
   
  
  
  
  
   _
   ¡¢¥©¡¢¡¦¡¢¡¢¥Ã¡¢¥Ë¥Õûö#58759;¥Ï¡¦¡¢¡¦ò§¥±¡¦¥Í¥Ò#63730;¥³¥ï MSN 
¡¦¥å¡¦æ§ò§¥Ã¡¦¥½¡£¥· 
 http://character.msn.co.jp/
  
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
 
 
 __
 Do You Yahoo!?
 Yahoo! Finance - Get real-time stock quotes
 http://finance.yahoo.com
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 _
 ²ñ°÷ÅÐÏ¿¤Ï̵ÎÁ¡¦½¼¼Â¤·¤¿½ÐÉÊ¥¢¥¤¥Æ¥à¤Ê¤é MSN ¥ª¡¼¥¯¥·¥ç¥ó 
 http://auction.msn.co.jp/
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

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




Re: [PHP] alter switch variable inside case?

2002-08-31 Thread @ Edwin
It seems like you can do something like this:

switch ($foo) {
   case 'a':
 if (do_a()) echo "a was done";
 else print_menu(); // changes here
   break;

   case 'b':
 if (do_b()) echo "b was done";
 else print_menu(); // changes here
   break;

   case 'menu':
 print_menu();
   break;

   case 'logout':
 do_logout();
   break;
}

Or, if for some reason you can't do that (or you don't want to)...

Here's another way: (I'm not sure if this will work.)

switch ($foo) {
   case 'a':
 if (do_a()) echo "a was done";
 else $foo='menu';
   
   case 'menu':
 print_menu();
   break;

   case 'b':
 if (do_b()) echo "b was done";
 else $foo='menu';

   case 'menu':
 print_menu();
   break;

   case 'logout':
 do_logout();
   break;
}

It doesn't look "clean" but it might just work...

BTW, I know this is just an example, but I expect you're doing your 

  if(){
  } else {
  }

properly in your real code...

- E


Regardless of how many break statements you take away (even
if only 1), case statements appear to be ignored after the
first match is made. I need a way to make the switch statement
continue evaluating case-matches, even after the first case
match is made. Further, it should allow one case segment to
alter the switch variable and have such alteration taken
into account for subsequent matches.

Here's a more illustrative example of my situation:

switch ($foo) {
   case 'a':
 if (do_a()) echo "a was done";
 else $foo='menu';
   break;

   case 'b':
 if (do_b()) echo "b was done";
 else $foo='menu';
   break;

   case 'menu':
 print_menu();
   break;

   case 'logout':
 do_logout();
   break;
}

that code will not print_menu if do_a fails, since
it exits the switch statement upon seeing a break.

if I remove the break after do_a, it will execute
do_a and do_b -- bad. what we really want is for it
to execute do_a and if do_a returns false, print_menu.

Joe

--- "@ Edwin" [EMAIL PROTECTED] wrote:
  Well, you don't have to take away all the "break;". :)
 
  For example, only here:
 
switch ($foo) {
  case 'step2':
  do_step2();
  if ($error) $foo='step1'; //repeat step1
  break;
 
  - E
 
  
  
  If you don't break, it continues to execute all the code until
  the end of the switch, ignoring any subsequent case
  statements.
  
  In my example, eliminating the break after step2 would
  cause execution of do_step1(), but also do_something_else(),
  which is not desired.
  
  --- "@ Edwin" [EMAIL PROTECTED] wrote:
Actually, you can--just don't "break;".
   
Try it.
   
- E
   

I'd like to be able to modify the switch variable inside a case
statement, like this:

switch ($foo) {
   case 'step2':
 do_step2();
 if ($error) $foo='step1'; //repeat step1
   break;

   case 'step1':
 do_step1();
   break;

   case 'a_third_thing':
 do_something_else();
   break;
}

Can you modify the variable ($foo) inside a case statement and
have it evaluated for subsequent 'case's like this? If not, I
will have to revert to a series of if statements, in which this 
can
be done:

if ($foo=='step2') {
   do_step2();
   if ($error) $foo='step1';
}
if ($foo=='step1') {
   do_step1();
}
etc.

Switch-case seems cleaner, and I'd prefer to stick with it.

__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com

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

   
   
   
   
_

$B!#!V!&%%!#!V!#%r!#!V!#!V!&%F!#!V!&%R!&%f|\(B#58759;$B!&%^!#%r!#!V!#%r(B#57822;$B!&%"!#%r!&%X!&%a(B#63730;$B!&%&!&!&(B
MSN $B!#%r!#%rl)(B#57822;$B!&%F!#%r!&%9!#!W!&%-(B
  http://character.msn.co.jp/
   
   
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   
  
  
  __
  Do You Yahoo!?
  Yahoo! Finance - Get real-time stock quotes
  http://finance.yahoo.com
  
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
  _
  
$B%$(B#57643;#58792;$B%_%^%=!"%^%U%*%[%A!#%r%9%7%7%D!"%-!"%=%9%_%N%O!&!V!&!"!&%K!&`&%O!"!&(BMSN
 $B!&%'!#%7!&%C!&%-!'!&(B 
 http://auction.msn.co.jp/
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 


__
Do You Yahoo!?
Yahoo! Finance - Get real-time stock quotes
http://finance.yahoo.com




_
$B%O%$%;%s%9$J>$r5$7Z$K9XF~(B MSN