Question

Bad news Everyone,

I recently started to learn FORTRAN to understand a code and translate it to C++ (I
know what the code does is not important for this question, but to give some background,
this code solves boundary value problems using collocation method on an adaptive grid).
Looking at the code, there are certain "go to" statements combined with "do continue"
that really confuse me.

Here is an example:

do 100 i=1, n
    C DO SOMETHING HERE
    if (some condition) go to 90
    C DO SOME MORE STUFF HERE
    90 continue
    C EVEN MORE STUFF HERE
100 continue

I have some experience programming in C, so I'll code my two interpretations in C as
follows, but I'm not sure which one (if any!) is the correct translation:

for(int i=1;i<=n;i++)
{
    //DO SOMETHING HERE
    if(some condition) continue;
    //DO SOME MORE STUFF HERE
    //EVEN MORE STUFF HERE
}

or:

for(int i=1;i<=n;i++)
{
    //DO SOMETHING HERE
    if(!some condition)
    {
        //DO SOME MORE STUFF HERE
    }
    //EVEN MORE STUFF HERE
}

I was wondering if anyone can help me understand the syntax.

Was it helpful?

Solution

The continue statement of Fortran does nothing. It is only there as a reference to jump to. In your Fortran code, the program jumps over DO SOME MORE STUFF HERE if some condition is true. Thus, your 2nd C version is correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top