CRPence | 23 Jul 23:13 2013
Picon

Re: Leave outside of DO group???

On 23 Jul 2013 13:48, DrFranken wrote:
> I wrote this snippet of code:
>
> Do
>  ChkObj QSTRUPEX1 *Pgm /* Check for exit program. */
>  MonMsg CPF9800 EXEC(Leave) /* Not there or Not Authorized */
>  Call QSTRUPEX1 /* Run it. */
>  MonMsg CPF0000
> EndDo
>
>
> At the LEAVE Statement I get this error:
> * CPD0883 30 LEAVE command found outside of DO group.
>
> But it sure appears to be inside a Do group to me!
>
> Am I in error if I 'complain' to the fine folks in the land of IBM
> i?
>

   AFaIK the error is correct, and ...

   The implied command label [CMDLBL(*CURRENT)] is, as worded in the 
message CPD089A, is not "associated with an active DOWHILE, DOUNTIL, or 
DOFOR group".  The additional\second-level text of that CPD0883 [e.g. as 
presented by F1=Help] should further state that "The LEAVE command must 
be inside a DOWHILE, DOUNTIL, or DOFOR command group."

   FWiW: Coding the MONMSG CPF0000 as shown is not a good practice; just 
as well remove the prior CHKOBJ and MONMSG to get effectively the same 
(Continue reading)

Dan Kimmel | 23 Jul 23:51 2013

RE: Leave outside of DO group???

Still, I like the concept. It'd be a way to get out of a block of code without a GOTO. The Do .. EndDo marks the
block of code. Are there other ways to jump out of a block in CL structured op codes?

> -----Original Message-----
> From: midrange-l-bounces@... [mailto:midrange-l-
> bounces@...] On Behalf Of CRPence
> Sent: Tuesday, July 23, 2013 4:13 PM
> To: midrange-l@...
> Subject: Re: Leave outside of DO group???
> 
> On 23 Jul 2013 13:48, DrFranken wrote:
> > I wrote this snippet of code:
> >
> > Do
> >  ChkObj QSTRUPEX1 *Pgm /* Check for exit program. */
> >  MonMsg CPF9800 EXEC(Leave) /* Not there or Not Authorized */
> >  Call QSTRUPEX1 /* Run it. */
> >  MonMsg CPF0000
> > EndDo
> >
> >
> > At the LEAVE Statement I get this error:
> > * CPD0883 30 LEAVE command found outside of DO group.
> >
> > But it sure appears to be inside a Do group to me!
> >
> > Am I in error if I 'complain' to the fine folks in the land of IBM
> > i?
> >
> 
(Continue reading)

Booth Martin | 23 Jul 23:58 2013

Re: Leave outside of DO group???

Could he do a NOT/Else  with the NOt MonMsg... else leave?

On 7/23/2013 4:51 PM, Dan Kimmel wrote:
> Still, I like the concept. It'd be a way to get out of a block of code without a GOTO. The Do .. EndDo marks the
block of code. Are there other ways to jump out of a block in CL structured op codes?
>
>> -----Original Message-----
>> From: midrange-l-bounces@... [mailto:midrange-l-
>> bounces@...] On Behalf Of CRPence
>> Sent: Tuesday, July 23, 2013 4:13 PM
>> To: midrange-l@...
>> Subject: Re: Leave outside of DO group???
>>
>> On 23 Jul 2013 13:48, DrFranken wrote:
>>> I wrote this snippet of code:
>>>
>>> Do
>>>   ChkObj QSTRUPEX1 *Pgm /* Check for exit program. */
>>>   MonMsg CPF9800 EXEC(Leave) /* Not there or Not Authorized */
>>>   Call QSTRUPEX1 /* Run it. */
>>>   MonMsg CPF0000
>>> EndDo
>>>
>>>
>>> At the LEAVE Statement I get this error:
>>> * CPD0883 30 LEAVE command found outside of DO group.
>>>
>>> But it sure appears to be inside a Do group to me!
>>>
>>> Am I in error if I 'complain' to the fine folks in the land of IBM
(Continue reading)

John McKee | 24 Jul 01:17 2013

Re: Leave outside of DO group???

I'm confused.  I had a teacher, years ago, who was adamant - one way
in and one way out.  How is LEAVE considered structured?  Violates the
teacher's rule, since there are now multiple ways that a loop could be
exited.  His preferred method was to test at the top.

I don't mean to start an argument.  Just trying to understand how
multiple exit paths is considered structured.

I have had to debug programs with multiple exit paths.  Process was
more involved.

John McKee

On Tue, Jul 23, 2013 at 4:58 PM, Booth Martin <booth@...> wrote:
> Could he do a NOT/Else  with the NOt MonMsg... else leave?
>
> On 7/23/2013 4:51 PM, Dan Kimmel wrote:
>> Still, I like the concept. It'd be a way to get out of a block of code without a GOTO. The Do .. EndDo marks the
block of code. Are there other ways to jump out of a block in CL structured op codes?
>>
>>> -----Original Message-----
>>> From: midrange-l-bounces@... [mailto:midrange-l-
>>> bounces@...] On Behalf Of CRPence
>>> Sent: Tuesday, July 23, 2013 4:13 PM
>>> To: midrange-l@...
>>> Subject: Re: Leave outside of DO group???
>>>
>>> On 23 Jul 2013 13:48, DrFranken wrote:
>>>> I wrote this snippet of code:
>>>>
(Continue reading)

Alan Campin | 24 Jul 01:29 2013
Picon

Re: Leave outside of DO group???

This has been argued a hundred times in this forum. If you are a purist,
Leave and Iterate are not structured. The problem is that they just work.
You write better code.

On Tue, Jul 23, 2013 at 5:17 PM, John McKee <jmmckee@...> wrote:

> I'm confused.  I had a teacher, years ago, who was adamant - one way
> in and one way out.  How is LEAVE considered structured?  Violates the
> teacher's rule, since there are now multiple ways that a loop could be
> exited.  His preferred method was to test at the top.
>
> I don't mean to start an argument.  Just trying to understand how
> multiple exit paths is considered structured.
>
> I have had to debug programs with multiple exit paths.  Process was
> more involved.
>
> John McKee
>
> On Tue, Jul 23, 2013 at 4:58 PM, Booth Martin <booth@...> wrote:
> > Could he do a NOT/Else  with the NOt MonMsg... else leave?
> >
> > On 7/23/2013 4:51 PM, Dan Kimmel wrote:
> >> Still, I like the concept. It'd be a way to get out of a block of code
> without a GOTO. The Do .. EndDo marks the block of code. Are there other
> ways to jump out of a block in CL structured op codes?
> >>
> >>> -----Original Message-----
> >>> From: midrange-l-bounces@... [mailto:midrange-l-
> >>> bounces@...] On Behalf Of CRPence
(Continue reading)

James H. H. Lampert | 24 Jul 01:37 2013

Re: Leave outside of DO group???

On 7/23/13 4:17 PM, John McKee wrote:
> I'm confused.  I had a teacher, years ago, who was adamant - one way
> in and one way out.  How is LEAVE considered structured?  Violates the
> teacher's rule, since there are now multiple ways that a loop could be
> exited.  His preferred method was to test at the top.

Many years ago, there was a level of fanaticism involving structured 
programming, combined with a very primitive understanding of it. It was 
exemplified in the inordinate popularity of Pascal, which had no concept 
of "LEAVE," and only grudgingly included a GOTO.

This primitive understanding assumed, in particular, that under normal 
conditions, an indexed loop always runs to completion, and should only 
exit early in case of an irrecoverable error. In fact, there's an 
obvious exception to this: table look-up. This led to numerous cases in 
which programmers were forced to choose between (1) storing the "found" 
value and continuing to waste processor resources iterating uselessly 
(perhaps at least skipping the "meat" of the loop), (2) substituting a 
DOWHILE or DOUNTIL construct, and handling the counter manually, or (3) 
using a GOTO.

It's rather telling that when Niklaus Wirth, the ultimate structured 
programming maven, designed a language for actual production use (Pascal 
was never intended as more than a teaching language), it *did* have a 
"LEAVE" (I don't remember, offhand, what it was called).

At any rate, where GOTO allows transfer of control to any labeled 
statement (in some languages, like traditional BASIC, all statements 
have labels), possibly even including transferring *into* a loop or 
inner-block in a way that bypasses any initialization, LEAVE simply 
(Continue reading)

DrFranken | 24 Jul 01:44 2013

Re: Leave outside of DO group???

I like James' explanation here but I stay more on the Practical side. If 
I copy a chunk of code or move a chunk of code and there are "GoTo" 
instructions I must carefully analyze the tags and determine if they 
also must be moved or if new ones must be created. Failure to do so can 
break program logic very badly. With a loop that utilizes Leave in 
addition to a normal exit 'at the bottom' it's very easily portable with 
essentially no risk to primary program flow.

Translation: I am lazy. :-)

         - Larry "DrFranken" Bolhuis

www.frankeni.com
www.iDevCloud.com
www.iInTheCloud.com

On 7/23/2013 7:37 PM, James H. H. Lampert wrote:

> Many years ago, there was a level of fanaticism involving structured
> programming, combined with a very primitive understanding of it. It was
> exemplified in the inordinate popularity of Pascal, which had no concept
> of "LEAVE," and only grudgingly included a GOTO.
>
> This primitive understanding assumed, in particular, that under normal
> conditions, an indexed loop always runs to completion, and should only
> exit early in case of an irrecoverable error. In fact, there's an
> obvious exception to this: table look-up. This led to numerous cases in
> which programmers were forced to choose between (1) storing the "found"
> value and continuing to waste processor resources iterating uselessly
> (perhaps at least skipping the "meat" of the loop), (2) substituting a
(Continue reading)

Jon Paris | 24 Jul 03:01 2013

Re: Leave outside of DO group???

No my little MQC - you are practical - not lazy.

I hate goto with a passion. Have been burnt by it so many times.

I've never been burnt by Leave or Iter - both are obvious, clear, unambiguous. Purists can scream all they
want, they work. Often code written to avoid them is far worse.

On 2013-07-23, at 7:44 PM, DrFranken <midrange@...> wrote:

> I like James' explanation here but I stay more on the Practical side. If 
> I copy a chunk of code or move a chunk of code and there are "GoTo" 
> instructions I must carefully analyze the tags and determine if they 
> also must be moved or if new ones must be created. Failure to do so can 
> break program logic very badly. With a loop that utilizes Leave in 
> addition to a normal exit 'at the bottom' it's very easily portable with 
> essentially no risk to primary program flow.
> 
> Translation: I am lazy. :-)
> 
>         - Larry "DrFranken" Bolhuis
> 
> www.frankeni.com
> www.iDevCloud.com
> www.iInTheCloud.com

Jon Paris

www.partner400.com
www.SystemiDeveloper.com

(Continue reading)

James H. H. Lampert | 24 Jul 17:26 2013

Re: Leave outside of DO group???

On 7/23/13 4:44 PM, DrFranken wrote:
> I like James' explanation here but I stay more on the Practical side. If
> I copy a chunk of code or move a chunk of code and there are "GoTo"
> instructions I must carefully analyze the tags and determine if they
> also must be moved or if new ones must be created.

The two are not mutually exclusive: it is precisely the avoidance of 
crazy jumping around (which, back in the days when interpretive BASIC 
was as common as cowpats, and software was frequently distributed as 
BASIC source code, was often used as a primitive form of obfuscation) 
that makes code that uses only LEAVE and/or ITERATE more structured, and 
therefore more portable.

--
JHHL

--

-- 
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@...
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@...
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.

John Yeung | 24 Jul 05:38 2013
Picon

Re: Leave outside of DO group???

Overall, I think James gives a very nice explanation of early
structured programming.

I feel like defending Pascal a bit, as I think it deserved its
popularity; and while it was designed primarily for teaching, it was
also designed to be efficient and clear, which is good not just for
students but for real-world programming.  With only minor tweaks,
Pascal was a nice implementation language, and used extensively by
Apple in development of the Lisa and early Mac.  At $50, Turbo Pascal
allowed legions of home computer hobbyists to graduate from
line-numbered Basic to a "grown up" language.  Including a stunningly
capable and fast IDE, complete with debugger!  It was nothing short of
a revelation.

Niklaus Wirth's later programming languages were, in effect, merely
his own tweaks to Pascal.  Probably the best-known of these is
Modula-2.  It used EXIT as the keyword for breaking out of loops.

John
--

-- 
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: MIDRANGE-L@...
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@...
Before posting, please take a moment to review the archives
at http://archive.midrange.com/midrange-l.

rob | 24 Jul 13:05 2013

Re: Leave outside of DO group???

I find LEAVE much better than
dowhile &moon='BLUE'
  ACTION
  MONMSG CPF0000 CHGVAR(&moon) value('PINK')
  If &moon<>'BLUE'
    ...
    ...
    ...
    6,000 lines of code later
    ...
    ...
    ...
  endif
  /* someone inserts line here, oopsie */
enddo

Rob Berendt
--

-- 
IBM Certified System Administrator - IBM i 6.1
Group Dekko
Dept 1600
Mail to:  2505 Dekko Drive
          Garrett, IN 46738
Ship to:  Dock 108
          6928N 400E
          Kendallville, IN 46755
http://www.dekko.com

From:   John McKee <jmmckee@...>
To:     Midrange Systems Technical Discussion <midrange-l@...>, 
(Continue reading)

John McKee | 24 Jul 13:25 2013

Re: Leave outside of DO group???

True, it appears better.  But, then, there is another "standard" where
conditioned code should not extend over pages.  I have seen vendor
code where I work that violates that,  Six levels deep over the
equivalent of ten printed pages.  One program was so ugly that when I
was applying vendor supplied code changes, it failed to compile.  I
contacted the vendor and got issue resolved, but I also asked if
anybody considered rewriting the thing.  Answer I got was that nobody
wanted to risk it.

Pretty close to your comment about 6000 lines later.  I pity anybody
who has to work on that thing.

John McKee

On Wed, Jul 24, 2013 at 6:05 AM,  <rob@...> wrote:
> I find LEAVE much better than
> dowhile &moon='BLUE'
>   ACTION
>   MONMSG CPF0000 CHGVAR(&moon) value('PINK')
>   If &moon<>'BLUE'
>     ...
>     ...
>     ...
>     6,000 lines of code later
>     ...
>     ...
>     ...
>   endif
>   /* someone inserts line here, oopsie */
> enddo
(Continue reading)

Re: Leave outside of DO group???

Sometimes this principle causes unnecessary nesting or duplication of code.  Say you are reading a file. Do
you have two read statements, or do you introduce an extra level of nesting in the loop to avoid processing
after no record found?

read
do while not eof
  process
  read
end do

or

do until eof
  read
  if not eof
    process
  end if
end do

or short cut it

do while true
  read
  if eof then leave
  process
end do

The best practices being violated are (respectively):
* do not repeat yourself
* minimize nesting
(Continue reading)

rob | 24 Jul 16:29 2013

Re: Leave outside of DO group???

Excellent example.  I thought of a read loop and the priming read also.

Of course, moving your read to a subprocedure that returns a Boolean helps 
cut that out.

dowhile GetRow;
  // process read
EndDo;

And, as you've said, it is a balance on which principle to apply.

Rob Berendt
--

-- 
IBM Certified System Administrator - IBM i 6.1
Group Dekko
Dept 1600
Mail to:  2505 Dekko Drive
          Garrett, IN 46738
Ship to:  Dock 108
          6928N 400E
          Kendallville, IN 46755
http://www.dekko.com

From:   "Mark Murphy/STAR BASE Consulting Inc." <mmurphy@...>
To:     Midrange Systems Technical Discussion <midrange-l@...>, 
Date:   07/24/2013 10:00 AM
Subject:        Re: Leave outside of DO group???
Sent by:        midrange-l-bounces@...

Sometimes this principle causes unnecessary nesting or duplication of 
(Continue reading)

Wes Reinhold | 24 Jul 16:31 2013

RE: Leave outside of DO group???

I think the first example illustrates a 'primed' do loop.  Have
everything set before you enter processing.  This is the way they taught
us back in the '70s.  I have also seen this presented in COMMON
sessions.

-----Original Message-----
From: midrange-l-bounces@...
[mailto:midrange-l-bounces@...] On Behalf Of Mark Murphy/STAR
BASE Consulting Inc.
Sent: Wednesday, July 24, 2013 10:01 AM
To: Midrange Systems Technical Discussion
Subject: Re: Leave outside of DO group???

Sometimes this principle causes unnecessary nesting or duplication of
code.  Say you are reading a file. Do you have two read statements, or
do you introduce an extra level of nesting in the loop to avoid
processing after no record found?

read
do while not eof
  process
  read
end do

or

do until eof
  read
  if not eof
    process
(Continue reading)

DrFranken | 24 Jul 01:40 2013

Re: Leave outside of DO group???

Yes I agree that the help text is correct but logically why did they 
omit a standard "Do" ?   I'm guessing that it's too late to change now 
because if someone has coded:

DoWhile xxx
    (...)
    MonMsg CPF1234 EXEC(Do)
	(...)
	Leave	<<<<--------
	EndDo
EndDo

That Leave will exit the DoWhile. If they changed it to also exit the 
Do/EndDo then existing code is broken.

Now as to the MONMSG CPF0000 that is there because this is part of a 
Startup Job and we want that to continue.  The ChkObj is used elsewhere 
in order to only call the program IF it exists.

Also Stylistically I generally hate the "Damn the Torpedoes" approach.

         - Larry "DrFranken" Bolhuis

www.frankeni.com
www.iDevCloud.com
www.iInTheCloud.com

On 7/23/2013 5:13 PM, CRPence wrote:

> On 23 Jul 2013 13:48, DrFranken wrote:
(Continue reading)


Gmane