Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand the original question, the question is actually an interesting one. Rewording the question (to what I think is an equivalent question): "How do you do a FORTRAN computed goto in C?"</p> <p>First we need to know what a computed goto is: Here is a link to one explanation: <a href="http://h21007.www2.hp.com/portal/download/files/unprot/fortran/docs/lrm/lrm0124.htm" rel="nofollow">http://h21007.www2.hp.com/portal/download/files/unprot/fortran/docs/lrm/lrm0124.htm</a>.</p> <p>An example of a computed GOTO is:</p> <pre><code> GO TO (12,24,36), INDEX </code></pre> <p>Where 12, 24, and 36 are statement numbers. (C language labels could serve as an equivalent, but is not the only thing that could be an equivalent.)</p> <p>And where INDEX is a variable, but could be the result of a formula.</p> <p>Here is one way (but not the only way) to do the same thing in C:</p> <pre><code>int SITU(int J, int K) { int raw_value = (J * 5) + K; int index = (raw_value % 5) - 1; return index; } int main(void) { int J = 5, K= 2; // fortran computed goto statement: GO TO (320,330,340,350,360), SITU(J,K) + 1 switch (SITU(J,K) + 1) { case 0: // 320 // code statement 320 goes here printf("Statement 320"); break; case 1: // 330 // code statement 330 goes here printf("Statement 330"); break; case 2: // 340 // code statement 340 goes here printf("Statement 340"); break; case 3: // 350 // code statement 350 goes here printf("Statement 350"); break; case 4: // 360 // code statement 360 goes here printf("Statement 360"); break; } printf("\nPress Enter\n"); getchar(); return 0; } </code></pre> <p>In this particular example, we see that you do not need C gotos to implement a FORTRAN computed goto!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload