On Sat, 19 Jun 2021, at 23:47, Bob Bridges wrote:
> Peter Sylvester's post reminded me (for no reason I can identify) of
> something else I do in any language that doesn't have an EXIT DO
> statement.
>
> For example, something like this:
>
> /* is this a user we want to process? */
> do
> if name='' then exit do /* no */
> if st<>'NC' then exit do /* no */
> amount=GetAmount(userID)
> if amount>9999 then exit do /* no */
> call ProcessUser; end
>
> A SELECT won't do it, if I cannot invoke GetAmount until the user has
> passed the first two tests (and certainly I'd rather not anyway).
Really? What's wrong with
select
when name='' then nop
when st<>'NC' then nop
when GetAmount(userID) > 9999 then nop
otherwise call ProcessUser
end
? The only difficulty is that you might need the value of "amount"
in the following code, but that just means that you need to have
thought about that and made GetAmount() also set it via expose.
Or, one might change GetAmount so that as well as setting Amount
via expose, it returns a flag if that value would have been out of
range, and you test the flag. That might be clearer.
The best way to solve this depends on whether GetAmount is to be
used elsewhere, in which case you design it to fit all its uses, and
compromise in the instance that doesn't work so well.
There'd be nothing wrong with the less elegant
select
when name='' then nop
when st<>'NC' then nop
otherwise do
amount = GetAmount(userID)
if amount <= 9999 then call ProcessUser
end
--
Jeremy Nicoll - my opinions are my own.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN