Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question of profound interest,

Status
Not open for further replies.

bobo12

Programmer
Dec 26, 2004
74
US
hi,
i am converting a gizzilion lines of fortran to java and i have come to ask you experienced ppl of how to deal with GOTO STATEMENTS and lables in the translation. u c, java's labeling capabilities are very weak so i am wondering if there is a better solution than setting flags.

here is an example of what i am asking...
0 IF (KK1(K+1) .GT. 9) GO TO 35
IF (KK1(K+2) .GT. 9) GO TO 40
IF (KK1(K+3) .GT. 9) GO TO 45
WRITE (*,*) ' Invalid item number, do you want to try ',
1 'again? (Y/N)'
READ (*,'(A)') ANS
IF (ANS .EQ. 'Y') GO TO 1
STOP
35 N2 = N2 + 1
KK2(N2) = KK1(K)
K = K + 1
GO TO 150
40 N2 = N2 + 1
KK2(N2) = KK1(K) * 10 + KK1(K+1)
K = K + 2
GO TO 150
45 N2 = N2 + 1
 
The easiest way to convert code with gotos is to draw an old fashioned flowchart and then write the java code according to the flowchart. I don't know Java - this is the equivalent in C++
Code:
for (;;)
{
   if (kk1[k+1] > 9)
   {
      // label 35 bit

      // goto 150
      break;
   }
   else if (kk1[k+2] > 9)
   {
      // label 40 bit
   }
   else if (kk1[k+3] > 9)
   {
      // label 45 bit
   }
   else
   {
      cout << "Invalid item number, do you want to try again? (Y/N)" << endl;
      cin >> ans;
      if (ans != 'y') exit (0);
      // Presumably this is in a loop of some sort
      continue;
   }
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top