× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



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.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.