I am analyzing a code in fortran and have a simple question.
I want to know what the "continue" statement at 100 and 200 in the code below does.
Does it increment the i and j counters? If so, wouldn't if( .not. flg )
then condition contain the flg
value that is the "last value" of flg in the loop j = i+1 to N
?
do 100 i = 1, N-1
flg = .false.
do 200 j 开发者_运维技巧= i+1, N
if( "my condition" ) flg = .true.
200 continue
if( .not. flg ) then
! do something here.
endif
100 continue
AFAIK, CONTINUE in fortran does nothing.
It's used only for convenience in DO loop semantics. This is not like C.
Th CONTINUE statement simply marks the end of the loop indicated by its numeric statement number - it doesn't increment anything. It certainly has no effect on flg in your code. There's a simple explanation of its use here.
This is old Fortran, which used typically used labeled continue statements to mark do loops. Fortran 90 and later provides an "end do" statements.
I am answering after more than three years since the question was asked in Feb'2010 because I saw the question now only and find that the answers would have been more detailed and complete. Indeed the logical variable flg shall have "last value" of flg in the loop j = i+1 to N because the inner do loop designated by label 200 shall run from j = i+1 to N for each value of i (= 1, N-1,1). The condition "my condition" must plays important role in not making this inner loop trivial otherwise.
精彩评论