Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29253 Discussions

Value of loop variable outside the loop

ingo_berg
Beginner
586 Views
I'd like to know what if the value of a loop variable after the loop is defined. I'd like to determine if a loop was terminated by exit or not. Currently I use the following code, which works fine:

do iDim=1, size(STRDIM,1)
if (STRDIM(iDim)==strTokBuf(1)) exit
end do

if (iDim==4) then
call Panic("unsupported keyword: $VAL1$", strTokBuf(1))
end if

were STRDIM is a global variable defined as:
character(LEN=*), parameter :: STRDIM(3) = (/"COLUMN", &
"ROW ", &
"LAYER "/)

If the loop did not exit prematurely the value of the loop variable is size(STRDIM,1)+1.

Is this always true according to the fortran standard?
0 Kudos
1 Reply
TimP
Honored Contributor III
586 Views
Yes, the f77 standard introduced this requirement. http://www.fortran.com/fortran/F77_std/f77_std.html
I have not seen a compiler in 15 years which did not implement it.
0 Kudos
Reply