Thread overview | ||||||
---|---|---|---|---|---|---|
|
June 02, 2008 returning a break? | ||||
---|---|---|---|---|
| ||||
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 |
June 02, 2008 Re: returning a break? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rui Coelho Justino | "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* |
June 02, 2008 Re: returning a break? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | 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 :-P > > 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* Thanks, that is in deed a nice solution. |
June 02, 2008 Re: returning a break? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rui Coelho Justino | "Rui Coelho Justino" <rmcjustino@gmail.com> wrote in message news:g21l71$22sn$1@digitalmars.com... > 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 :-P You can't return a break in Python either.. |
Copyright © 1999-2021 by the D Language Foundation