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



Personally, I never use SELECT in RPG.


-----Original Message-----
From: john erps [mailto:jacobus.erps@xxxxxxxxx]
Sent: Tuesday, September 10, 2019 5:36 AM
To: rpg400-l@xxxxxxxxxxxxxxxxxx
Subject: IF..ELSEIF vs SELECT

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?


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.