![Advantech UbiQ Скачать руководство пользователя страница 57](http://html1.mh-extra.com/html/advantech/ubiq/ubiq_user-manual_2856809057.webp)
51
UbiQ Scenario Manager User Manual
Chapter 4
B
asic of
Smart-C
S
cript
Language
(3) If cond-expression is false (0), execution of the for statement terminates and con-
trol passes to the next statement in the program.
A for statement also terminates when a break or return statement within the state-
ment body is executed. A continue statement in a for loop causes loop-expression to
be evaluated. When a break statement is executed inside a for loop, loop-expression
is not evaluated or executed.
This example illustrates the for statement:
for ( i = 0; i < MAX; i=i+1 )
{
if ( line[i] == '\n' )
new_line=ne1;
}
First i is initialized to 0. Then i is compared with the constant MAX; if i is less than
MAX, the statement body is executed. Depending on the value of line[i], the body of
one or neither of the if statements is executed. Then i is incremented and tested
against MAX; the statement body is executed repeatedly as long as i is less than
MAX.
if statement
The if statement controls conditional branching. The body of an if statement is exe-
cuted if the value of the expression is nonzero. The syntax for the if statement has
two forms.
Syntax
if-statement :
if ( expression ) block-statement
if ( expression ) block-statement else block-statement
In the first form of the syntax, if expression is true (nonzero), block-statement is exe-
cuted. If expression is false, block-statement is ignored. In the second form of syntax,
which uses else, the second block-statement is executed if expression is false. With
both forms, control then passes from the if statement to the next statement in the pro-
gram unless one of the statements contains a break, continue.
The following are examples of the if statement:
if ( i > 0 ) {
y = x / i;
}
else
{
x = i;
Содержание UbiQ
Страница 1: ...User Manual UbiQ Scenario Manager User Manual V1 03...
Страница 4: ...UbiQ Scenario Manager User Manual iv...
Страница 7: ...Chapter 1 1 Introduction...
Страница 13: ...Chapter 2 2 Getting Started...
Страница 37: ...Chapter 3 3 Tutorials...
Страница 47: ...Chapter 4 4 Basic of Smart C Script Language...
Страница 62: ...UbiQ Scenario Manager User Manual 56...
Страница 63: ...Chapter 5 5 Functions Reference...