Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if elseif else implementation in Netlogo environment

Tags:

netlogo

I wish - if elseif else statement in NetLogo. How can I do so efficiently? I checked NetLogo documentation no command to do so. Previous similar question didn't answer it directly but solved in the context.

One simple solution is:

    let flag true
    if(condition1)
    [
    ...
    set flag false
    ]
    if(flag and condition2)   ;else if statement
    [
    ...
    set flag false
    ]
    if(flag)  ;else statement
    [

    ...
    ]

I am looking for others more efficient ones.

Edit: added flag in the second if condition upon Nicolas's suggestion.

like image 362
Abhishek Bhatia Avatar asked Oct 20 '22 12:10

Abhishek Bhatia


1 Answers

The only way I can wholeheartedly recommend is:

ifelse condition1
  [ ... ]
  [ ifelse condition2
      [ ... ]
      [ ifelse condition3
        [ ... ]
        [ ifelse ...

But yeah, the indentation and readability aren't great. For thoughts on possible eventual improvements, see https://github.com/NetLogo/NetLogo/issues/344 and https://github.com/qiemem/ControlFlowExtension.

like image 195
Seth Tisue Avatar answered Dec 10 '22 14:12

Seth Tisue