"A.D. Fundum" <what...@neverm.ind> wrote:
>What's a fast but readable Rexx-way to replace a lot of IFs?
>
>The number of nested IFs and memory usage is becoming a bigger problem
>than the speed, I'm about to ask what the nesting limit is. I can
>think of several solutions, one will do. Words? Array of names?
>Another surprise?
I think it's going to depend on what your different IFs are doing (unless
you really do mean the example below?), and also how many times it's going
to be executed. A sneakier method might be faster but require more time
spent setting something up.
>IF name<>'Fred' THEN DO
> IF name<>'Freddy' THEN DO
> IF name<>'Saundra' THEN DO
> IF name<>'Sandra' THEN DO
> IF name<>'F' THEN DO
> ...
> IF name<>'S' THEN SAY 'Accepted!'
I'd usually use for this
namelist = "Fred Freddy Saundra Sandra F S"
if wordpos(name,wordlist) == 0 then say "Accepted"
However it looks to me as if you might also be looking at abbreviations
(perhaps of any length?) of the names. For example, would you need to
consider SA, SAU, SAUN etc? That suggests to me that Abbrev() might need to
play a part. But then again, especially if there were many potential names
maybe I'd statically or dynamically create:
nams.F = "F FR FRE FRED FREDD FREDDY"
nams.S = "S SA SAN SAU SAND SAUN SANDR SAUND SANDRA SAUNDR SAUNDRA"
then: namelet1 = substr(name,1)
namelist = nams.namelet1
if wordpos(translate(name),wordlist) == 0 then ...
Of course if you need to put meaningful code at any of the other points in
the IF / IF / IF structure, then none of this will work.
--
Jeremy C B Nicoll - my opinions are my own.
Email sent to my from-address will be deleted. Instead, please reply
to
newsre...@wingsandbeaks.org.uk replacing "aaa" by "284".