Even they are redundancy I use SELECT and IF/ELSEUF them "differently".
If I check different entries within the same variable(s), I use SELECT. For
examples
Select;
When FLDA = 'A';
When FLDB = 'B;
...
EndSL;
Or
Select
When FldX = 'A' and FldY = 'B';
When FldX = 'X' and FldY <> 'B'
When FldX <> 'A' and FldX <> 'X' and FldY = 'C'
...
EndSL
If I have to check different conditions I use IF / ELSEIF. For examples:
If FLDA = 'X' and FLDB = 'Y';
ElseIF FLDC = 1;
...
Else;
EndIf
Or
(Param3 and Param2 are different fields)
If %Parms >= %ParmNum(Param3) and Param3 > '';
ElseIf %Parms >= %ParmNum(Param2) and Param2 > *Zeros;
...
Else;
EndIf;
... but these are only my private rules
Mit freundlichen Grüßen / Best regards
Birgitta Hauser
"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"
?Train people well enough so they can leave, treat them well enough so they
don't want to.? (Richard Branson)
-----Original Message-----
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Mark
Murphy
Sent: Freitag, 25. Januar 2019 22:02
To: rpg400-l@xxxxxxxxxxxxxxxxxx
Subject: select vs. if-elseif
Does anyone else find the redundancy between the select block and the
if-elseif-else block a little disconcerting? Seems to me that there should
be a clear distinction between the two. There never can be at this point, so
I tend to use a relatively inconsistent mix of the two in my code based on
what mood I am in. But the select syntax has a potentially game changing
syntax.
select <variable>;
when <value>;
...
when <value>;
...
when <value>;
...
other;
...
endsl;
This syntax reduces redundancy in a significant amount of code, by reducing
the need to retype code variable names over and over again.
Wouldn't it be nice?
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (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.