Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question about Goto syntax 2

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
US
I have some code that has a bunch of tags. Some of the tags are just numbers, while others have the word
continue after them. What is the difference between the two?
Code:
201	         IF(ISAT.EQ.WLDATM.AND.IAAT.EQ.CARBON) CHKRA=1
	         CHKRI=1
	         GOTO 300

202	         IF(ISAT.EQ.WLDATM.AND.IAAT.EQ.OXEGEN) CHKRA=1
	         CHKRI=1
	         GOTO 300


216	         CONTINUE
	         RN=3
	         GOTO 21900

217	         CONTINUE
	         RN=4
	         GOTO 21900

 
Not a lot.

Most people use

200 CONTINUE
IF ( something ) GOTO 999

because it's easier to modify by inserting lines than

200 IF ( something ) GOTO 999

Well, at least it used to be easier to modify if you were using a line editor... if anyone remembers them?

Also commonly used as the terminating statement in DO loops.

 
The tags are labels so you can GOTO them. CONTINUE is just a dummy statement. In your example, you will probably find a GOTO 201, GOTO 202, GOTO 216 and GOTO 217 somewhere in the code. Sometimes the tags are used for loop termination. eg
Code:
      DO 999 I = 1, 10, 1
         DO 999 J = 1, 10, 1
         ...
999   CONTINUE
999 will terminate both loops. Sometimes they are used to identify FORMAT statements
Code:
      WRITE (10, 888) I, J
888   FORMAT (1X, 'I = ', I2, 'J = ', I9)
They can also be used in assigned goto statements.
Code:
      ASSIGN 9876 TO EXIT_CAVE
      ...
      GOTO EXIT_CAVE
      ....
9876  CONTINUE
 
Thanks for your feedback. Your explanations cleared up my problem. I'm converting the go statements into while loops.
 
If you ever see any code with ASSIGNED GOTOs in it, be afraid, be very afraid...
 
It isn't just GOTOs - you can assign them to any label like those for FORMAT statements.

Is there an obfuscated FORTRAN contest???
 
I've never tried to GOTO a format statement.

Wonder what it does...

I've only seen the ASSIGNED GOTO used once.

It was a particularly horrid piece of programming that someone used to avoid coding a subroutine... just used ASSIGN 1000 TO JUMP to GOTO the subroutine and ASSIGN 500 TO JUMP to return from it.

Nasty.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top