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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With