Fortran DO command

  • Fortran
  • Thread starter zandria
  • Start date
  • #1
15
0

Main Question or Discussion Point

I am working with visual Fortran (f90 I believe)

I have the following program and it says that I have 2 errors. I have narrowed it down to having something to do with my loop statement in bold. Is there something wrong that I'm not getting?

program exercise1

implicit none

integer :: limit, f1, f2, f3
read*, limit

f1 = 1
if (limit >= 1) then
print*, f1
end if

f2 = 1
if (limit >= 2) print*, f2

do i= 3, limit
f3 = f1 + f2
print*, f3
f1 = f2
f2 = f3
end do



end program exercise1
 

Answers and Replies

  • #2
15
0
nevermind, figured it out. I did not define "i" as a variable in my list of integers
 
  • #3
6
0
Remove (delete) the statement: implicit none
 
  • #4
minger
Science Advisor
1,495
2
DO NOT REMOVE THE IMPLICIT NONE STATEMENT

Having that in forces the user to explicitly define their variables. Removing that statement to get a program to compile will nearly always cause problems later down the line.

Simply put: fix it right the first time.
 
  • #5
jtbell
Mentor
15,578
3,557
Without the IMPLICIT NONE, if you mis-spell the name of a variable once, the compiler doesn't catch it for you, as an undeclared variable. Instead, it cheerfully allocates a new variable with that name, which has no connection with the variable you meant to use. Your program compiles "successfully," but when you run it, it either produces incorrect results or crashes with a run-time error that can be very difficult to track down.
 

Related Threads on Fortran DO command

  • Last Post
Replies
7
Views
5K
  • Last Post
Replies
4
Views
2K
Replies
6
Views
14K
Replies
5
Views
1K
Replies
7
Views
4K
Replies
3
Views
2K
Replies
1
Views
3K
Replies
3
Views
1K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
14
Views
874
Top