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
GO TO
program demo
i = 0
48 i = i + 1
print*, i
if (i .lt. 10) goto 48
end
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
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
Got it. Brilliant...thanks
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.
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.