Could anybody shed some light on when to use IF..ELSEIF and SELECT.
This was discussed not too long ago in the archives:
https://archive.midrange.com/rpg400-l/201901/msg00184.html
I also found a discussion from December 2004. I imagine this topic has
come up several times in between.
I suspect that initially [SELECT] would be just like a CASE statement, but, IBM
being IBM, and camels and committees.... it ends up as another way of
writing IF...ELSEIF.
No, the history is that SELECT predates ELSEIF, and was designed from
the beginning to handle open-ended conditions, not merely match a
selection variable. So the redundant addition (for RPG) is the ELSEIF.
Why did they bother introducing ELSEIF if SELECT already handled
arbitrary conditions? I suspect (just a guess) that there was a lot of
legacy nested IF..ELSE (possibly predating the introduction of
SELECT), with a train of ENDs at the end, and either too many
programmers were not warming to SELECT, or it was just felt that there
was value in preserving a sort of "visual intuitiveness" of
nested-but-more-compact IF..ELSE.
Though the language doesn't enforce it, various people use their own
restrictions for when to use SELECT, most commonly as a
single-variable CASE statement. It has also been mentioned that you
could alternate when nesting (within one branch of an ELSEIF, use
SELECT to do the next level of branching; within a SELECT, use ELSEIF
to do the next level of branching). Surely there are a few other
conventions that one could choose if they wanted.
John Y.
As an Amazon Associate we earn from qualifying purchases.