我是Fortran的新手(我的意思是我5分钟前开始),我一直在搞乱,我知道如何打印开始/结束程序以及if语句的if部分。不过,我遇到的问题是其他部分。它不断出现错误:
ELSE() print *, "x did not = 1"
1
Error: Unexpected junk after ELSE statement at (1)
这是我的代码:
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
答案 0 :(得分:1)
示例代码的正确结构应类似于:
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
请注意,第25行的if语句后接'then'关键字,而您的选项被else语句除以
。也不需要行号。我只是在这里使用它,所以我可以在答案中引用该行。