forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GO TO

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
dahowarduk



Joined: 24 Jun 2020
Posts: 11

PostPosted: Sun Jul 05, 2020 8:50 pm    Post subject: GO TO Reply with quote

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
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 697
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Sun Jul 05, 2020 9:03 pm    Post subject: Reply with quote

Code:
      program demo
      i = 0
48    i = i + 1
      print*, i
      if (i .lt. 10) goto 48
      end
Back to top
View user's profile Send private message Visit poster's website
dahowarduk



Joined: 24 Jun 2020
Posts: 11

PostPosted: Sun Jul 05, 2020 11:12 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Kenneth_Smith



Joined: 18 May 2012
Posts: 697
Location: Hamilton, Lanarkshire, Scotland.

PostPosted: Sun Jul 05, 2020 11:43 pm    Post subject: Reply with quote

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:-

Quote:
1 program demo
2 i = 0
3 48 i = i + 1
4 print*, i
5 if (i .lt. 10) goto 48
6 end
Back to top
View user's profile Send private message Visit poster's website
dahowarduk



Joined: 24 Jun 2020
Posts: 11

PostPosted: Mon Jul 06, 2020 8:56 am    Post subject: Reply with quote

Got it. Brilliant...thanks
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Mon Jul 06, 2020 9:07 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message AIM Address
dahowarduk



Joined: 24 Jun 2020
Posts: 11

PostPosted: Mon Jul 06, 2020 9:11 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group