New Reply

Fortran 90, goto

 
Share Thread Thread Tools
Apr1-11, 10:58 PM   #1
 
Recognitions:
Gold Membership Gold Member

Fortran 90, goto


I don't understand why I get an error when I use the goto "command" like this:


(...)

goto 11

(...)

11 end program


----------------------------------------------------------
The (...) represent the other part of my program. I tried to change the place of the 11. Because if I compile my program with the "11 end program" line I get the error "Label 11 referenced at (1) is never defined" so basically it doesn't see the 11 in front of "end program".
When I changed the place of the "11" the program could compile.
Can someone explain me why fortran can't see the 11 in front of the end program?
Now I need to think about a substitute of my original idea.
 
PhysOrg.com
PhysOrg
science news on PhysOrg.com

>> Front-row seats to climate change
>> Attacking MRSA with metals from antibacterial clays
>> New formula invented for microscope viewing, substitutes for federally controlled drug
Apr1-11, 11:13 PM   #2
 
Mentor
Try attaching the statement number to a "continue" statement right before the "end program" statement. I suspect the problem is that "end program" is not an executable statement, but simply a signal (directive) to the compiler. You might as well try to put a statement number on a "dimension" statement.
 
Apr1-11, 11:14 PM   #3
 
End is not an executable statement it's a compiler directive. Use this:

11 STOP
END
 
Apr2-11, 07:29 PM   #4

Math 2012
 
Recognitions:
Science Advisor Science Advisor

Fortran 90, goto


I would prefer
11 CONTINUE
or
11 RETURN
rather than
11 STOP

If you use a "stop" statement, you may get some output saying "program terminated by stop statement at line xxx in subprogram main" or something similar.

Even better, replace the
GOTO 11
with
RETURN
 
Apr2-11, 07:57 PM   #5
 
Recognitions:
Gold Membership Gold Member
Thanks guys. My program now compile and works well (I believe. I must test an .and. command but I think it works great).
Instead of stopping the program as I initially thought, I redirect to the statement before a "if (...)
end if" so basically my program restart from a certain point.

So the main problem is that "end program" is not an executable statement... wow.
 
Jul15-12, 06:54 AM   #6
 
i have similar problem in go to statement. i get a warning, please answer my problem rapidly.
go to 3
.
.
.
.
.
3 write(10,*),"variables=x,y,say"
.
.
.
.
end program
 
Jul15-12, 07:56 AM   #7
 
post your warning rapidly
 
Jul15-12, 12:21 PM   #8
 
Mentor
Quote by azar8 View Post
please answer my problem rapidly.
We will answer your problem rapidly when we get around to it.
 
Jul15-12, 03:45 PM   #9
 
warning is:
Warning: A jump into a block from outside the block has occurred. [3]
 
Jul15-12, 04:36 PM   #10

Math 2012
 
Recognitions:
Science Advisor Science Advisor
A "block" is something like a DO loop, or an IF ... THEN .. ELSE ... ENDIF structure.

If you write code like
Code:
GOTO 10
...
DO I = J, K
...
10 ...
...
ENDDO
It isn't very obvious what should happen at the ENDDO statement, because I, J and K might not have any values, or they might have values that mean you shouldn't be executing the code insude the loop at all.
Similarly for
Code:
IF (X .GT. 0}
...
10 ...
...
ELSE
...
ENDIF
you could junp to label 10 when X was not > 0.

An optimising compiler might generate code that just doesn't work at all in those situations. For example at statement 10 the compiler should be able to assume that X really is greater than 0, so dividing by X can't produce a "divide by zero" error when the program runs, or evaluating X**0.25 can't prodice an error saying "X is negative", etc.

That's why Fortran says it is illegal to jump into a block from outside - though your compuler let you off with a warning message instead of an error.
 
Jul26-12, 07:59 AM   #11
 
GOTO's are a poor programming practice in Fortran. It is a desperate last resort which results in spaghetti code.
 
Jul28-12, 06:15 PM   #12
 
Hey guys could any one teell me a print format by which i could print 3 arrays as a table like first array on the first column and the second array on the second colomn,,, in short i just want to print 3 RRAYS TOGETHER as a table each array ON ONE COLUMN


thanks in advance
 
Jul30-12, 07:16 AM   #13
 
Hardy, you might want to create a new thread with a more clear definition on what you need help with. You just randomly posted in someone's thread, in case you didn't realize.
 
Jul30-12, 12:56 PM   #14
 
Mentor
Quote by hardy03 View Post
Hey guys could any one teell me a print format by which i could print 3 arrays as a table like first array on the first column and the second array on the second colomn,,, in short i just want to print 3 RRAYS TOGETHER as a table each array ON ONE COLUMN
Please start a new thread.
 
New Reply
Thread Tools


Similar Threads for: Fortran 90, goto
Thread Forum Replies
Nambu-Goto String Beyond the Standard Model 0
The Nambu-Goto Action Beyond the Standard Model 0
search for a label than a trailing right brace Programming & Comp Sci 90
Accessing Fortran Modules within a Fortran library from Fortran Programming & Comp Sci 0
Goto statements Programming & Comp Sci 25