- 积分
- 1901
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2015-1-6
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2016-5-31 14:56:22
|
显示全部楼层
有点儿清醒了,哈哈
官方教程language_man
--------------------------------
Section 2.6 Statements
Statements are the fundamental element of NCL. Everything NCL does happens only
after a statement is entered. Statements are case sensitive and are not restricted to
being a single line of source, and statements can be nested within statements. There are
17 different kinds of statements: assignment, procedure call, function definition,
procedure definition, block, do, if-then, if-then-else, break, continue, setvalues,
getvalues, return, record, new, stop, and quit.
Section 2.7 Loops
NCL provides two kinds of do loops: a while loop that repeats until its
scalar_logical_expression evaluates to False, and a traditional do loop that loops from a
start value through an end value incrementing or decrementing a loop variable either by
one or by a specified stride.
do n=start,end,optional_stride
[statement(s)]
end do ; space is required
do while (scalar_logical_expression)
[statement(s)]
end do
With each kind of loop, the keywords break and continue can be used.
break: jump to first statement after end do
continue: proceed directly to the next iteration
Use of loops should be minimized in any interpreted language. Often, loops can be
replaced by array syntax or a built-in function. If multiple do loops are required and
execution speed is a concern, linking codes written in Fortran or C may be the best
approach. (Section 7.)
Section 2.8 Blocks and if statements
Blocks provide a way to group a list of statements. Since blocks are statements, the
statements within the begin and end do not get executed until the end statement is
parsed and the source is determined to be free of syntax errors. The use of begin and
end is optional for the main or driver script.
begin ; optional but recommended
[statement(s)]
end ; required if begin present
There are two kinds of if statements: the if-then statement and the if-then-else
statement. These function like if statements in other popular programming languages.
if (scalar_logical_expression) then
[statement(s)]
end if
if (scalar_logical_expression) then
[statement(s)]
else
[statement(s)]
end if
|
|