|
On Sep 10, 2019, at 9:30 AM, Justin Taylor <JUSTIN@xxxxxxxxxxxxx> wrote:
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?
--
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 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.