Fixing Fortran DO Command Errors for Visual Fortran (f90)

  • Fortran
  • Thread starter zandria
  • Start date
  • Tags
    Fortran
In summary, the user is working with visual Fortran and has encountered 2 errors in their program. They have narrowed it down to a potential issue with their loop statement, but have since figured out the problem. The user also mentions the importance of using the "implicit none" statement in order to avoid potential errors and ensure proper variable definition.
  • #1
zandria
15
0
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
 
Technology news on Phys.org
  • #2
nevermind, figured it out. I did not define "i" as a variable in my list of integers
 
  • #3
Remove (delete) the statement: implicit none
 
  • #4
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
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 to Fixing Fortran DO Command Errors for Visual Fortran (f90)

1. What is a DO command error in Fortran?

A DO command error in Fortran occurs when there is a mistake in the syntax or structure of the DO loop, which is a repetitive control structure used in the language. This can cause unexpected or incorrect behavior in the program.

2. How do I fix a DO command error in Visual Fortran?

To fix a DO command error in Visual Fortran, you can start by carefully checking the syntax of the DO loop. Make sure all necessary components are included and in the correct order. You can also use a debugger or print statements to track the flow of the loop and identify any logic errors.

3. Are there any common mistakes that lead to DO command errors?

Yes, there are a few common mistakes that can lead to DO command errors in Fortran. These include forgetting to include a closing statement for the DO loop, using incorrect data types or variables within the loop, and not properly incrementing or decrementing the loop index variable.

4. How can I prevent DO command errors in my Fortran code?

To prevent DO command errors in your Fortran code, it is important to carefully plan and structure your DO loops. Make sure to use clear and descriptive variable names, double check the syntax, and test the loop with different inputs to ensure it is functioning correctly.

5. Is there any online support or resources available for fixing DO command errors in Fortran?

Yes, there are many online resources available for fixing DO command errors in Fortran. Some helpful sites include the official Fortran language website, online forums and communities, and tutorials and guides specifically focused on debugging Fortran code.

Similar threads

  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
5
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
13
Views
2K
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
4
Views
641
  • Programming and Computer Science
Replies
17
Views
4K
  • Programming and Computer Science
Replies
17
Views
5K
  • Programming and Computer Science
Replies
20
Views
2K
Back
Top