回 帖 发 新 帖 刷新版面

主题:关于goto语句

goto(10,20,30,40,50,60),X
这种语句是表示什么意思?

回复列表 (共10个回复)

沙发

if (x .eq. 1) goto 10
if (x .eq. 2) goto 20
...

板凳

可是我的X只有5个值啊

3 楼

不想说太多,提高水平网上问固然是一个方法,但我们不要太依赖别人,尽管有人热心回答,但自己动手才丰衣足食;这个问题,说实在话,我开始并不知道 goto 的语法,因为这个是 Fortran95 废弃的语法,我压根儿就不想学。若是要用,怎么办。
    第一, 我可以查帮助文档,这个是唯一的、最可信、最全面的参考资料,无论是谁,水平有多么高,都可以从中学到东西的。
    第二,我可以 Debug,看看 goto 到底怎样 Control 线程,试几个 expr 的值,也就大概知道 goto 语法的含义了。
    这个就是熟练的程序员和菜鸟的区别。

附 CVF 帮助文档:

GOTO - Computed
Statement: Transfers control to one of a set of labeled branch target statements based on the value of an expression. It is an obsolescent feature in Fortran 95.

Syntax

GOTO (label-list) [ , ] expr


label-list
Is a list of labels (separated by commas) of valid branch target statements in the same scoping unit as the computed GO TO statement. (Also called the transfer list.) The same label can appear more than once in this list.


expr
Is a scalar numeric expression in the range 1 to n, where n is the number of statement labels in label-list. If necessary, it is converted to integer data type.
Rules and Behavior

When the computed GO TO statement is executed, the expression is evaluated first. The value of the expression represents the ordinal position of a label in the associated list of labels. Control is transferred to the statement identified by the label. For example, if the list contains (30,20,30,40) and the value of the expression is 2, control is transferred to the statement identified with label 20.

If the value of the expression is less than 1 or greater than the number of labels in the list, control is transferred to the next executable statement or construct following the computed GO TO statement.

Compatibility

CONSOLE STANDARD GRAPHICS QUICKWIN GRAPHICS WINDOWS DLL LIB

See Also: GOTO - Unconditional GOTO, Execution Control

Examples

The following example shows valid computed GO TO statements:

GO TO (12,24,36), INDEX
GO TO (320,330,340,350,360), SITU(J,K) + 1

The following shows another example:

   next = 1
C
C  The following statement transfers control to statement 10:
C
   GOTO (10, 20) next
   ...
10 CONTINUE
   ...
20 CONTINUE

4 楼

If the value of the expression is less than 1 or greater than the number of labels in the list, control is transferred to the next executable statement or construct following the computed GO TO statement.
那么长,好象这句有用,不过还不是很明白

PS:不是我们想依赖你们,只是作为一个初学者,我们不懂的实在太多;看英文也很不懂;再者,作为一个论坛没有采鸟就没有新鲜血液,SO I 认为菜鸟无罪!!!

5 楼

goto(10,20,30,40,50,60),X
你的5个X值也许是1,2,3,4,5;也许是2,3,4,5,6;也许是1,2,4,5,6。
如果x肯定是1,2,3,4,5,则括号中的60没用,是冗余的垃圾。这也是为什么F90往后版本将这种语句列为要淘汰的语法。

6 楼

If the value of the expression is less than 1 or greater than the number of labels in the list, control is transferred to the next executable statement or construct following the computed GO TO statement.

以你的问题为例,如果x<0或者x>6,则转到下一句可执行语句。

7 楼

明白了
谢谢老师

8 楼

感谢mltx耐心回答!
这个问题,半个月前,我问过mltx老师。
我问的原因是我没有Fortran编译器,我只是做程序移植!
很感谢mltx老师。现在我的论文已经投稿了!多亏mltx老师帮忙!

9 楼

祝贺happyflybird论文投稿,这回真Happy了。:)

10 楼

If the value of the expression is less than 1 or greater than the number of labels in the list, control is transferred to the next executable statement or construct following the computed GO TO statement.

以你的问题为例,如果x<0或者x>6,则转到下一句可执行语句。


上面的  [size=1]x<0[/size]  好象为

x<1

我来回复

您尚未登录,请登录后再回复。点此登录或注册