Silverfrost Forums

Welcome to our forums

GO TO

5 Jul 2020 7:50 #25901

How do I construct a GOTO IN FTN95? I entered the line GOTO 48 and got the error message LABEL48 HAS NOT BEEN DEFINED. But I couldn't find out how to define a label. Thanks

5 Jul 2020 8:03 #25902
      program demo
      i = 0
48    i = i + 1
      print*, i
      if (i .lt. 10) goto 48
      end
5 Jul 2020 10:12 #25903

thanks..but that is sort of what I did...

43 GOTO 48 44
45 ENDIF 46
47 ENDDO 48 CALL SOLVE (CELL)

and I just get the message Label48 has not been defined.

What am I missing?

thanks

5 Jul 2020 10:43 #25905

The line numbers of the text file containing the code cannot be used as labels.

The line you want to jump to needs to be given a numerical label (conventionally in columns 1 to 5) and the GOTO statement points to that number.

In my example label 48 is on the third line. The advantage of this is if I then inset text above the third line, the GOTO statement still points towards the correct label even although its line number has changed.

Showing line numbers the above example appears as:-

1 program demo 2 i = 0 3 48 i = i + 1 4 print*, i 5 if (i .lt. 10) goto 48 6 end

6 Jul 2020 7:56 #25907

Got it. Brilliant...thanks

6 Jul 2020 8:07 #25908

dahowarduk

If you are a beginner then it is advisable to avoid using GOTO. Use other constructs such as IF/THEN and DO/ENDDO whenever possible.

GOTO can be found in old Fortran (pre Fortran 77) and is a nightmare to maintain - sometimes referred to a spaghetti code.

6 Jul 2020 8:11 #25909

Yes. I sort of remember that advice for many years ago. I think it was called 'structured programming'...1 way in and 1 way out . Before I got your solution, I'd managed an alternative process via using a DO WHILE, which kept to the 'structured' approach.

Please login to reply.