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



Hi,

I personally distinguish between IF/ELSEIF and SELECT:

IF/ELSEIF is used, if the conditions are based on different fields, for
example:
If FldA = 1;
   // DoA
ElseIf FldB = 2;
   // DoB
ElseIf FldC = 'X';
   // DoC
Else;
   // DoElse
EndIf;

SELECT/WHEN is used, if I have to check different conditions of the same
field:
Select;
When FldA = 1;
    //DoA1
When FldA = 2;
    //DoA2
When FldA = 3;
    //DoA3
Other;
    //DoOther;
EndSL;

Mit freundlichen Gru?en / Best regards

Birgitta

"Shoot for the moon, even if you miss, you'll land among the stars."
(Les Brown)

-----Ursprungliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]Im Auftrag von Joe Pluta
Gesendet: Donnerstag, 25. Mai 2006 23:06
An: 'RPG programming on the AS400 / iSeries'
Betreff: RE: Having both if/else executing at the same time


> From: AGlauser@xxxxxxxxxxxx
>
> Joe,
>
> I'm interested in your reasons for using select/when over if/elseif.  I
> think I prefer if/elseif only because I learned about them first, and to
> me case-like statements should fall through like they do in C.  It seems
> redundant to me to have both structures behave identically, and awkward to
> have to do:

I like the semantics of "When this, do this" rather than "if this, do this,
else if this, do this".  I understand your point about the difference
between the C switch and the RPG select because I also learned switch a long
time ago, but frankly the C switch statement leaves a lot to be desired, and
accidentally forgetting a break has caused no end of debugging problems (not
to mention reading "clever" programs where things fall through and different
options share some code).

I would like enhancements to the SELECT, such as being able to do something
if the first condition is met, but then be able to do something if it is NOT
met, and then test other conditions.  For example, read one record and if it
has a certain value, do something.  Otherwise, read a different record and
then do one of three things based on a field in that record.  Of course I
can do it with IF/ELSE/ENDIF, but it's just not as neat, especially as the
indenting creeps in.

Joe


--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.




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.