List Info

Thread: Re: Equivalent to Select Case Statement




Re: Equivalent to Select Case Statement
country flaguser name
United States
2008-03-07 15:05:22

Hi, Ola!

The netlogo way to emulate a select or switch statement is to use a nested if-else structure.

For example:


                                    
  if-else option1 [ action1 ] [     

  if-else option2 [ action2 ] [     
  if-else option3 [ action3 ] [     
           ;        otherwise-action ;
  ]]]     ;           ;           ;    
         ;           ;           ;     


To preserve the formatting and clarity of the structure, it's good to use only short commands, or procedure calls as the action, but that is a code-style issue, not a code-running issue.

Note that there will always be one right square bracket at the end for each if-else, so, three options = three brackets.

Note that even if there is no "otherwise-action", the last if-else can remain an if-else, there's no need to break the symmetry and use IF instead.

Hope this helps,

~~James
_________________
www.turtlezero.com

On Thu, Mar 6, 2008 at 8:25 PM, Ola Olsson < oeolssonenosis.net">oeolssonenosis.net> wrote:
&gt; Hello,
>;  
>;  I9;m trying to get a handle on all the NetLogo commands. Is there an
>  equivalent command or preferred set of commands that will replicate
>  the "select case" statement found in other languages? Currently I
>  have to set a boolean variable at the top of my procedure then
>  traverse through a bunch of if statements until one is satisfied then
>  set my variable to false so the procedure doesn't waste its time with
>;  the subsequent ifs.
>  
>;  Best Regards,
&gt;  Ola Olsson
>;  --
&gt;  Cheers,
>  Ola Olsson
>;  
>;  /*******************************************
>  /** oeolssonenosis.net">oeolssonenosis.net -- http://www.enosis.net
>  /** "There is a time for laughing
&gt;  /**  and there is a time not for laughing.
>  /**  This is not one of them.";
>  /*******************************************

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )