How to convert GO TO (Fortran77) to Matlab

Click For Summary
SUMMARY

The discussion focuses on converting Fortran77 code that utilizes the GO TO statement into equivalent Matlab code, which does not support this construct. The user presents a specific code snippet where the GO TO statement is embedded within conditional statements. The solution proposed involves replacing the GO TO with a loop structure that uses the "continue" statement to manage flow control, allowing the program to skip to the next iteration when conditions are met.

PREREQUISITES
  • Understanding of Fortran77 programming constructs, specifically the GO TO statement.
  • Familiarity with Matlab syntax and control flow structures.
  • Knowledge of conditional statements in programming, particularly "if" statements.
  • Experience with loop constructs in Matlab, including "for" and "while" loops.
NEXT STEPS
  • Research how to implement loops in Matlab, focusing on "for" and "while" loops.
  • Learn about the "continue" statement in Matlab and its usage within loop structures.
  • Explore best practices for translating legacy code from Fortran77 to modern programming languages.
  • Study conditional statements in Matlab to understand their syntax and behavior compared to Fortran77.
USEFUL FOR

This discussion is beneficial for software developers, particularly those involved in code migration from Fortran77 to Matlab, as well as programmers looking to enhance their understanding of control flow in different programming languages.

Triscas
Messages
9
Reaction score
0
I'm translating some code from Fortran77 to Matlab and I'm struggling due to the sentence GO TO is not valid in Matlab.
Usually using sentences while I can solve the problem but in a particular case I don't know how to face it.
To put in situation, i.e:

code
line 1
line 2
...
128 a=a+1

if c==1 && kcount < 20 then
line
line
if (h < 30) then
go to 128
end if
end if
line
line
if (zmax == 0) go to 128
if (zmin. lt. 0.999d0*zmax) go to 128
line
end

The problem, if can be apreciated, is the go to inside the double if statement that also is in normal if statements.


If it's neccesary I could write the code.

Thanks!
 
Physics news on Phys.org
You will most probably need to insert a loop starting at line 128. Details will depend on how the program terminates when it doesn't "go to 128" in the last if statement you wrote. Then at every instance of "go to 128", you would replace that with "continue", such that the rest of the code would be skipped and the loop would iterate, which is what appears to be happening here.
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K