www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - returning a break?

reply Rui Coelho Justino <rmcjustino gmail.com> writes:
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
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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
parent reply Rui Coelho Justino <rmcjustino gmail.com> writes:
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.
Jun 02 2008
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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..
Jun 02 2008