I’ve been tasked in a homework assignment with converting a loop in C# into Fortran 95.
outerLoop:
for(row = 0; row < numRows; rows++){
for(col = 0; col < numCols; col++){
if(mat[row][col] == 0)
continue outerLoop;
sum += mat[row][col];
}
}
As some of you can see, this looks similar to the exit statement label specification used in Java and Perl, which, to my understanding, are used to break out of loops that have nested loops or ‘if‘ statements rather than just a single loop/statement. I’m still new to this feature in Java, so I’m not sure if it exists anywhere else, specifically in C# and Fortran 95.
I’ve looked around on Google, but I haven’t found anything for it. I have a bad time formulating search terms to use on Google, so that factors into it, as well.
Please note: I’m not looking for a handout answer; I’m just looking for where to find the answer myself.
Thank you for taking time out to read this post.
I believe such a
break xfeature is not supported in C#. You would need to break out of the nested loops manually using flags.Simpler alternatives include the
gotostatement (which is widely frowned upon); and encapsulating your loop within a dedicated method, in which case, you could justreturnwhen you want to stop iterating.