Search code examples
javafortrangoto

Fortran GOTOs in java


Yes, I looked at various ways of implementing GOTO in java, but here is the real world: I need one of the latest fortran LAPACK routine converted to java, see http://www.netlib.org/lapack/timing/eig/eigsrc/dlasq3.f e.g.:

10 CONTINUE
      IF( N0.LT.I0 )
     $   RETURN
      IF( N0.EQ.I0 )
     $   GO TO 20
      NN = 4*N0 + PP
      IF( N0.EQ.( I0+1 ) )
     $   GO TO 40
      OPS = OPS + DBLE( 3 )
      IF( Z( NN-5 ).GT.TOL2*( SIGMA+Z( NN-3 ) ) .AND.
     $    Z( NN-2*PP-4 ).GT.TOL2*Z( NN-7 ) )
     $   GO TO 30
   20 CONTINUE
      fortran code ...
      GO TO 10
   30 CONTINUE
      OPS = OPS + DBLE( 2 )
      IF( Z( NN-9 ).GT.TOL2*SIGMA .AND.
     $    Z( NN-2*PP-8 ).GT.TOL2*Z( NN-11 ) )
     $   GO TO 50
   40 CONTINUE
      fortran code ...
      GO TO 10
   50 CONTINUE

What would be a "standard" way to deal with all possible GOTOs?


Solution

  • GOTOs are considered an anti-pattern. You should never try to convert it straight to Java without considering redesigning the code.

    For example, when you see a label for GOTO, that is likely a sign that this code would be reused. Should it belong in a method to be called again in the future instead? Approach the new design using OO rather than using the same procedural train of though as that in FORTRAN.

    Java does work in the real world without GOTOs.