Stuart,

 

I was thinking about this further as I was on my way to an appointment.
Allow me to offer some support for the "rules" we've been espousing.

 

IF/ENDIF  IF/ELSE/ENDIF

 

This construct begins with a simple logical comparison that is either TRUE
or FALSE.  If the comparison returns TRUE, the code before the ENDIF is
executed.  When an ELSE is included, that code will execute if the
comparison returns FALSE.  In this case, the ELSE serves as the code
delimiter for the TRUE case.

 

This is all very elementary, but the point in our context is that once the
IF statement has been evaluated, R:BASE knows to either execute or not
execute the subsequent code, depending on the logical result of the
comparison.  In other words, the program flow is then fully resolved.
Consequently, a GOTO in the middle of an IF/ENDIF does not disturb R:BASE's
ability to know what to do next.

 

WHILE/ENDWHILE

 

This construct says, in effect, "Execute this next block of code while a
logical comparison returns TRUE."  The comparison is evaluated at the TOP of
every iteration.  This is a key factor, and led to the need for the BREAK to
stop execution of the loop.  So two things can stop the loop - BREAK, and
the logical comparison evaluating FALSE at the top of the loop.  

 

Thus, a GOTO placed in the middle of a WHILE/ENDWHILE deprives R:BASE of the
ability to know that the looping is complete.  The programmer branches out
of the loop to who knows where, and R:BASE can quickly lose its way, all the
while thinking that it is still executing the loop.  Not a good condition.

 

SWITCH/ENDSW

 

This construct branches to one of a number of defined code blocks based upon
the value of the argument to SWITCH.  These blocks are delimited by CASE and
BREAK.  So when R:BASE enters a SWITCH, it finds the relevant CASE and
executes until it finds a BREAK; after the BREAK it immediately goes to the
first line of code after the ENDSW.

 

A GOTO in the middle of a CASE structure will therefore prevent R:BASE from
reaching the corresponding BREAK.  R:BASE continues to think it is executing
the CASE block, even if you transfer control to another code file.  Again,
the programmer has deprived R:BASE of the opportunity to correctly recognize
the code delimiter and close out the CASE and SWITCH.

 

Now, imagine if you combined a GOTO out of a WHILE with a subsequent SWITCH.
When R:BASE finally hits the BREAK (in this example the one for the CASE)
how is it to know whether this is the BREAK for the WHILE or for the CASE?
And the reverse case is also difficult to resolve - a GOTO out of a CASE
that hits a WHLE/ENDWHILE with a BREAK embedded . is this the BREAK for the
case or for the WHILE?

 

One would expect that R:BASE would work like the CPU does with the Stack,
pushing onto and popping from, and therefore know that in the latter example
the BREAK encountered is for the WHILE.  But there are simply so many
variables involved this cannot be assured.  First there is the code that
constitutes R:BASE itself, then the code of the language in which R:BASE is
written, then the compiler for that language, and the linker, and so on.
Plenty of opportunity exists for things to get turned around.  

 

Thus it becomes incumbent on the R:BASE programmer to exercise good
practice, making certain that R:BASE has the opportunity to reach the
statements that signal the end of WHILE/ENDWHILE and SWITCH/ENDSW
constructs.

 

Likewise, consider the folly of jumping into the middle of a WHILE/ENDWHILE
or SWITCH/ENDSW - you've not provided the context for the statements that
will signal the end of a construct.  When R:BASE hits the BREAK or the
ENDWHILE, it will not recognize that as a valid statement (and certainly
won't execute the loop in a WHILE  construct.)

 

Emmitt Dove

Manager, DairyPak Business Systems

Evergreen Packaging, Inc.

[EMAIL PROTECTED]

[EMAIL PROTECTED]

(203) 643-8022

 

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Stuart Cohen
Sent: Tuesday, January 22, 2008 6:05 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - RE: Two eyes are not good enough

 

Emmitt, Sammi and Dennis,

Once again, thank you very much for your insight.  It is very helpful!

Stuart J. Cohen, Ph.D.
Major, Medical Service Corps
Research Specialist
Walter Reed Army Medical Center
National Disaster Medical System Federal Coordinating Center
Phone: 202-782-3636
Cell: 301-514-3975
Fax: 202-782-4360
E-mail: [EMAIL PROTECTED]

Emmitt Dove wrote: 

Dennis,

 

That one deserves emphasis - do not use GOTO to jump into a construct.

 

On the other hand, a LABEL xxx with a GOTO xxx that exists inside an
IF/ENDIF works fine. 

 

Emmitt Dove

Manager, DairyPak Business Systems

Evergreen Packaging, Inc.

[EMAIL PROTECTED]

[EMAIL PROTECTED]

(203) 643-8022

 

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Dennis
McGrath
Sent: Tuesday, January 22, 2008 3:03 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - RE: Two eyes are not good enough

 

If RSTYLE complains, you'd better code it different.

If it does not complain, you are more likely to be successful.

 

You do not want to exit a Switch/EndSw or a While/EndW with a goto

 

If statements are just simple flow control constructs. 

You can goto OUT of them all you want. 

I would try to avoid gotoing INTO an if/endif block just because it is poor
form and may cause you some logical headaches.

 

Dennis McGrath

 

  _____  

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Stuart Cohen
Sent: Tuesday, January 22, 2008 1:42 PM
To: RBASE-L Mailing List
Subject: [RBASE-L] - RE: Two eyes are not good enough

 

Emmitt, Sami and Alastair:

I very much appreciate your comments regarding GOTO commands within SWITCH
blocks.  During the long weekend, I was pondering over your comments
regarding why GOTO commands could be a problem within SWITCH blocks,
especially since I have not had a problem with this situation.........yet.
Then it dawned on me!  The GOTO statement would skip over the BREAK and
ENDSW statements and can thus confuse the computer which is looking for
these statements to close the block.  It also dawned on me that IF blocks
have corresponding ENDIF statements to close them and (though I have never
put a GOTO command in one) WHILE loops have corresponding ENDWHILE commands
to close them.  Does this mean that a programmer should not put GOTO
statements within IF Blocks and WHILE loops?

Once again, thank you very much!

Stuart J. Cohen, Ph.D.
Major, Medical Service Corps
Research Specialist
Walter Reed Army Medical Center
National Disaster Medical System Federal Coordinating Center
Phone: 202-782-3636
Cell: 301-514-3975
Fax: 202-782-4360
E-mail: [EMAIL PROTECTED]

 

 

Emmitt Dove wrote: 

Stuart,

 

To pick up on Albert and Sami's observations about the GOTO from a switch
block, here is how I handle that:

 

SET VAR vlabel TEXT = 'somelabel'

SWITCH (.vwhatever)

  CASE 1

   { Some condition exists }

   SET VAR vlabel = 'thisotherlabel'

    BREAK

  CASE 2

    {a different condition exists}

    SET VAR vlabel = 'yetanotherlabel'

  DEFAULT

    BREAK

ENDSW

GOTO &vlabel

 

Emmitt Dove

Manager, DairyPak Business Systems

Blue Ridge Paper Products, Inc.

[EMAIL PROTECTED]

[EMAIL PROTECTED]

(203) 643-8022

 


Sami Aaron wrote: 

Stuart -

 

I see two possibilities:

 

 "IF variable = NULL  THEN" should be    "IF variable IS NULL THEN"

Within a SWITCH block, you should issue "BREAK" instead of using "GOTO
TheEnd".. The break will drop the programming call down to the next line
after the ENDSW line.

Sami

 

____________________________

Sami Aaron

Software Management Specialists

913-915-1971

[EMAIL PROTECTED]

 

 

 

Alastair Burr wrote: 

I may be completely wrong but I thought that GOTOs in SWITCH statements were
something to be avoided. Maybe it's that which is not working?

 

Regards,

Alastair.

 

 

 

Reply via email to