If statements with more than two options (like else if)
A Logo programming environment for Microsoft Windows
Brought to you by:
david_costanzo
Hello, when using an IF-structure I can easily prepare it for two options using IFELSE or TEST and IFTRUE and IFFALSE. But what when there are three options or more? Will I have to create a complicated cascade of IFs? As I see, there is no CASE or SWITCH-structure. What is the best way to solve the multi-options problem with IF?
I use series of
IFstatements. This doesn't look clumsy to me unless there's a "default" case.You could implement your own
SWITCHcommand that takes three inputs. Something like:TO SWITCH :value :cases :defaultWhere
:casesis a list of lists. Each sublist is a pair: a case value and an instruction list toRUNif:valueequals the case value. If none of the sublists match, thenRUN :default.It would be invoked like:
This is a very good solution. Once again, it proves to be easy to extend
FMSLogo in an ovious and meaningful way. Thank you.
Dr.-Ing. Manfred Zindel
Diplom-Mathematiker
mz@pbreport.de +49(0)176-34478812
Inhaber und Geschäftsführer
--
pbreport e.K.
Arbeitsgruppe für wissenschaftliche Evaluation
und Verlag - gegründet 2001
Sebastianstr. 43, 33178 Borchen (Dörenhagen)
HR Paderborn A 2466
Am 05.11.2020 um 03:05 schrieb David Costanzo:
Related
Support Requests: #14