Fixing Goto Error in Fortran 90 Program

  • Fortran
  • Thread starter fluidistic
  • Start date
  • Tags
    Fortran
In summary, the individual is experiencing an error when using the goto command in their program and is seeking an explanation for why the compiler cannot see the label in front of "end program." The conversation also includes suggestions for alternative statements to use instead of goto, as well as a discussion on the poor programming practice of using goto statements in Fortran. The conversation ends with a request for help in printing three arrays as a table.
  • #1
fluidistic
Gold Member
3,923
261
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.:rofl:
 
Technology news on Phys.org
  • #2
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.
 
  • #3
End is not an executable statement it's a compiler directive. Use this:

11 STOP
END
 
  • #4
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
 
  • #5
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.
 
  • #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
 
  • #7
post your warning rapidly
 
  • #8
azar8 said:
please answer my problem rapidly.
We will answer your problem rapidly when we get around to it.
 
  • #9
warning is:
Warning: A jump into a block from outside the block has occurred. [3]
 
  • #10
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.
 
  • #11
GOTO's are a poor programming practice in Fortran. It is a desperate last resort which results in spaghetti code.
 
  • #12
Hey guys could anyone 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 COLUMNthanks in advance
 
  • #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.
 
  • #14
hardy03 said:
Hey guys could anyone 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.
 

1. How do I debug a "Fixing Goto Error in Fortran 90 Program"?

One way to debug this error is to use a debugging tool specifically designed for Fortran, such as GDB or DDT. These tools can help identify the specific line of code causing the error and provide more detailed error messages than the Fortran compiler.

2. Why am I getting a "Fixing Goto Error" in my Fortran program?

This error is common in Fortran programs because the use of the "goto" statement is considered bad programming practice. It can lead to confusing and hard-to-maintain code, and is therefore not allowed in Fortran 90. The compiler is flagging this error to encourage you to find an alternative solution.

3. Can I use the "goto" statement in a Fortran 90 program?

No, the "goto" statement is not allowed in Fortran 90. It was considered a problematic programming practice and was removed from the language in this version. Instead, you can use other control structures such as "if" statements and "do" loops to achieve the desired behavior.

4. How can I fix a "Fixing Goto Error" in my Fortran program?

The best way to fix this error is to rewrite your code without using the "goto" statement. Consider using other control structures or breaking your code into smaller, more manageable subroutines. This will not only fix the error but also make your code more readable and maintainable.

5. Are there any exceptions to using the "goto" statement in Fortran 90?

Yes, there are a few exceptions to using the "goto" statement in Fortran 90. For example, it is still allowed in some forms of error handling and in certain legacy code. However, it is generally recommended to avoid using "goto" in Fortran 90 as much as possible.

Similar threads

  • Programming and Computer Science
Replies
12
Views
961
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
4
Views
607
  • Programming and Computer Science
Replies
5
Views
4K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
2
Replies
37
Views
3K
  • Programming and Computer Science
Replies
8
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
14
Views
2K
Back
Top