- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
the two forms below don't give the same result :
464 ! do m = 1,3
465 ! if (l2 == d(ntemp,m)) l = m
466 ! exit
467 ! end do
468 if (l2 == d(ntemp,1)) l = 1
469 if (l2 == d(ntemp,2)) l = 2
470 if (l2 == d(ntemp,3)) l = 3
in the first case I get l = 2 and 3 (correct answer) in the second. (naturly the "!" character is switched as needed !)
What is wrong ? (compiler 2013.3.163)
DAELIII
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Because of the EXIT statement in the DO loop, the loop is executed only once, with m = 1. If the comparison yields .FALSE., after the loop is exited the variable I will retain whatever value it had before the loop was entered.
Perhaps you mean to write, instead:
[fortran] if (l2 == d(ntemp,m)) then l = m exit endif [/fortran]- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In addition to exit issue previously discussed.
What are the values of l, l2 and d(ntemp,1:3) prior to entering code section given?
As the code is written, it is unknown to the reader as to if any of the if tests result in .true.
IOW l passes through the filter unchanged.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>Indeed the exit has to be included in the if branch
Doing so would not produce equivalent results (e.g. when all three in line if tests result in .true.)
Jim Dempsey

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page