× 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.



In some of the programming languages I know CASE is a somewhat more
efficient instruction than IF/ELSEIF. I don't know if that would be the
case (not pun intended) with RPG. On a personal level I find it a more
elegant and cleaner construct

Regards,
Luis

Sent from my Moto G phone. Please excuse my brevity.

On Tue, Sep 10, 2019, 06:36 john erps <jacobus.erps@xxxxxxxxx> wrote:

Hi,

Could anybody shed some light on when to use IF..ELSEIF and SELECT.

Seems to me that the semantics of SELECT is exactly the same as IF..ELSEIF.
SELECT just takes one line more (the SELECT).

In other languages such as Java or Javascript you have a CASE statement.
Maybe the idea is like this CASE statement. However a "normal" CASE
statement like this selects between different individiual values of a
variable. However, each WHEN statement in a SELECT is a full loagical
expression, hence just the same as IF..ELSEIF.

I use select when i need to condition using one variable. For example:
SELECT
WHEN X = 1
...
WHEN X = 2
...
ENDSL

However:
SELECT(X)
WHEN 1
...
WHEN 2
...
ENDSL

Would be a much better syntax, which resembles the CASE statement.

I suspect that initially it 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.

So better to shun it, and, for simplicities sake, always use IF..ELSEIF. Or
is there a good reason to use SELECT? E.g. to communicate that it is simply
a choice between values like CASE?
--
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com


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.