Precisely Speaking
February 04, 2012, 07:10:15 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: So what's news with you?  Tell us about it in "Getting To Know You"!
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: CONTINUE loops the program  (Read 1310 times)
DonQuixote
Uber-Pro
****
Posts: 99


To Dream the Impossible Dream...


« on: March 18, 2010, 09:39:32 AM »

I can't imagine why this is true; but it is.
UniData.  If you write a Basic program and put a CONTINUE statement with no associated LOOP the entire program executes again.  Unbelievable but true.
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #1 on: March 19, 2010, 06:32:03 AM »

No kidding?  What version?
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
DonQuixote
Uber-Pro
****
Posts: 99


To Dream the Impossible Dream...


« Reply #2 on: March 19, 2010, 11:28:09 AM »

UniData RDBMS 6.1
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #3 on: March 19, 2010, 12:04:03 PM »

Wow.  I did this on Unidata 7.1:

PRINT 'XYZ'
CONTINUE

...and found myself inside an endless loop.  See, that just goes to show the value of my standard advice to avoid CONTINUE and EXIT, right? Wink
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
Tom Pellitieri
Rock Star
*****
Posts: 165


Tom Pellitieri - Toledo, Ohio


« Reply #4 on: March 19, 2010, 01:40:20 PM »

I'm guessing that CONTINUE jumps to the start of the current loop.  Since the program example you've provided has no loop, that would be the start of the program - which is why you get an infinite loop.

UniData help states: "Tip: Use CONTINUE instead of GOTO in structured programs", and suggests that it makes the code easier to read and maintain.  To my mind, however, the CONTINUE statement is merely a GOTO statement with an implied label!  I find that the CONTINUE statement makes a program harder to follow, not easier, since I have to find the start AND end of the containing loop.  Rather than use:

IF (TEST = 1) THEN CONTINUE
(more stuff)

I would prefer to see

IF (TEST # 1) THEN GOSUB DO.STUFF
...
DO.STUFF:
(more stuff)
RETURN

Naturally, I try to avoid GOTO statements.  The one exception for me (at this point - don't look at my code from 10 years ago!) is to use GOTO ERR.EXIT or GOTO PGM.EXIT to gracefully abort a routine without having excessively nested "IF-THEN-ELSE" structures.  I would choose a "self documenting" GOTO over an ambiguous CONTINUE any day.

--Tom
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #5 on: March 19, 2010, 01:51:17 PM »

I would choose a "self documenting" GOTO over an ambiguous CONTINUE any day.

Here Here!!
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
DonQuixote
Uber-Pro
****
Posts: 99


To Dream the Impossible Dream...


« Reply #6 on: March 30, 2010, 08:58:41 AM »

Its so gratifying to know people like you.  Smiley
Logged
slestak
Uber-Pro
****
Posts: 69



« Reply #7 on: May 07, 2010, 02:29:42 PM »

I like the CONTINUE, but I always follow it with a comment, i.e.

CONTINUE;* release loop
Logged
precisonline
President/Chief Technologist
Administrator
Rock Star
*****
Posts: 1524



WWW
« Reply #8 on: May 07, 2010, 03:22:19 PM »

(with all due respect to old commercials...)

If you must drink, drink Dos Equis.
If you must drink and drive, drink Pepsi.
If you must jump somewhere in a program (in any form), use a comment.
Logged

-Kevin
Accidents "happen"; success, however, is planned and executed.
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.7 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!