digitalmars.D.learn - returning a break?
- Rui Coelho Justino (30/30) Jun 02 2008 Hello
- Jarrett Billingsley (11/32) Jun 02 2008 I'm not sure what language you're coming from. Returning flow control
- Rui Coelho Justino (3/15) Jun 02 2008 Thanks, that is in deed a nice solution.
- Jarrett Billingsley (3/7) Jun 02 2008 You can't return a break in Python either..
Hello as I'm starting to learn this great language I've it a wall. After some analise's I decided to go with a switch case, approach to solve my problem, so now I have one condition that if met will break the switch, then how can I create a function the will summarise that check and simply return a break(case 1), opposed to write on all case's the same code (case 2,3)? to clarify it: switch( int_case ) { case 1, 0: Stdout( "Print 1" ).newline; function_that_breaks ( int_to_verify ); case 2: Stdout( "Print 2" ).newline; if ( int_to_verify != 0 ) { break; } case 3: Stdout( "Print 2" ).newline; if ( int_to_verify != 0 ) { break; } } How should this function be setup? function_that_breaks ( int ) using "return break;" doesn't work. Thanks
Jun 02 2008
"Rui Coelho Justino" <rmcjustino gmail.com> wrote in message news:g21hut$1pa7$1 digitalmars.com...switch( int_case ) { case 1, 0: Stdout( "Print 1" ).newline; function_that_breaks ( int_to_verify ); case 2: Stdout( "Print 2" ).newline; if ( int_to_verify != 0 ) { break; } case 3: Stdout( "Print 2" ).newline; if ( int_to_verify != 0 ) { break; } } How should this function be setup? function_that_breaks ( int ) using "return break;" doesn't work.I'm not sure what language you're coming from. Returning flow control structures doesn't sound like a common feature. Just structure "case 1, 0:" like "case 2:" or "case 3:". case 1, 0: Stdout("print 1").newline; if(function_that_breaks(int_to_verify)) break; case 2: *shrug*
Jun 02 2008
Jarrett Billingsley wrote:I'm not sure what language you're coming from. Returning flow control structures doesn't sound like a common feature.Well maybe you are right. Python :-PJust structure "case 1, 0:" like "case 2:" or "case 3:". case 1, 0: Stdout("print 1").newline; if(function_that_breaks(int_to_verify)) break; case 2: *shrug*Thanks, that is in deed a nice solution.
Jun 02 2008
"Rui Coelho Justino" <rmcjustino gmail.com> wrote in message news:g21l71$22sn$1 digitalmars.com...Jarrett Billingsley wrote:You can't return a break in Python either..I'm not sure what language you're coming from. Returning flow control structures doesn't sound like a common feature.Well maybe you are right. Python :-P
Jun 02 2008