如何很好地使用Fortran语句标签? [英] How to use Fortran statement labels well?

查看:132
本文介绍了如何很好地使用Fortran语句标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究用Fortran 95编写的模型,这是我的新手。语句标签的概念似乎很奇怪,到目前为止,我只找到一种解释,认为标签可以由作者任意决定,通常以10为增量。

I'm working on a model written in Fortran 95, which I am completely new to. The concept of statement labels seems strange, and I've so far only found the explanation that the labels can be arbitrarily decided by the author, usually incrementing by 10's.

这些标签是否有实际用途,除了在语句结束处更容易挑选出来之外?以及关于如何标记的公认标准。

Are there any practical uses of these labels, other than picking out more easily where a statement is ending? AND a generally accepted standard on how to label.

推荐答案

我认为在现代Fortran中有用的语句标记的唯一方法是用于在使用 goto s时进行错误控制(是的,有时它们很有用-小心处理;-))。 Chapman 在过时下列出它们。

The only way I can think of statement labels being useful in modern Fortran is for error control when using gotos (yes, they can be useful sometimes - when handled with care ;-)). Chapman lists them under "obsolescent".

构造名称,有时可能对帮助读者理解您的代码很有用,例如对于大型循环或 if 语句。构造名称的另一种用法是高级循环控制,例如循环外循环时:

Construct names, on the other hand, might be useful sometimes to help the reader understand your code e.g. for large loops or if statements. Another use for construct names is advanced loop control, e.g. when cycling an outer loop:

outer: do i=1,10
  do ii=1,10
    if ( i == 2 .and. ii == 3 ) cycle outer
    z(ii,i) = 1.d0
  enddo
enddo outer

这篇关于如何很好地使用Fortran语句标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆