Reputation:
I am new to Fortran (I mean I started 5 mins ago) and i have been messing around and I know how to do prints start/end programs and the if part of the if statement. The problem I am having, though, is with the else part. It keeps coming up with the error:
ELSE() print *, "x did not = 1"
1
Error: Unexpected junk after ELSE statement at (1)
Here is my code:
program hello
x = 1
IF(x==1) print *, "Hello"
IF(x==1) x=2
IF(x==1) print *, "Oh it didnt work..."
ELSE() print *, "x did not = 1 yay it worked"
end program hello
Upvotes: 0
Views: 2881
Reputation: 4802
The correct structure for your example code should be similar to:
program hello
x = 1
if( x == 1) print *, 'hello'
if( x == 1) x=2
25 if( x == 1) then
print *, "oh it didn't work..."
else
print *, "x did not = 1 yay it worked"
endif
end program hello
Notice that the if statement in line 25 is followed by the 'then' keyword and you options are divided by the else statement.
Also the line number is not necessary. I just used it here so I could reference the line in my answer.
Upvotes: 1