PC SOFT

WINDEV的在线文档

  • Single-line conditional statement
  • Condition
  • Composite condition
文档页面当前正在翻译。对于此延迟我们深表歉意。
您可以自愿地帮助我们翻译您想要的文档段落,然后只需通过以下地址与我们联系:info@cn.windev.com
产品
WinDevWebDev-服务器代码WebDev-浏览器代码WinDev Mobile报表和查询
平台
WindowsLinuxWindows MobileWindows PhoneWindows Store appsAndroidAndroid Widget iPhone/iPad
语言
JavaPHPAjax用户代码(MCU)外部语言
数据库
HFSQLHFSQL Client/Server存储过程HF 5.5OLE DBODBC本地访问

The 如果 statement allows you to run action according to a condition.

18版本和更高版本
WinDevWindows Store apps This feature is available in Windows Store apps mode.
18新版本
WinDevWindows Store apps This feature is available in Windows Store apps mode.
WinDevWindows Store apps This feature is available in Windows Store apps mode.
例子
如果Customer.CalculatedAge大于60,那么
Elderly+=1
否则如果Customer.CalculatedAge大于18,那么
Adult+=1
否则如果Customer.CalculatedAge大于4,那么
Child+=1
否则
Baby+=1
结束

语法

Syntax 1

 如果 <Condition> THEN
  <Action if condition is True>
[ELSE
  <Action if condition is False>]
END

Syntax 2

 如果 <Condition> THEN
  <Action if condition is True>
[ELSE <Action if condition is False>]

Syntax 3 隐藏详细信息

 如果 <Condition> THEN <Action if condition is True> [ELSE <Action if condition is False>]

<IF>:
Marks the beginning of the statement block.
<Condition>:
Condition to check.
<THEN>:
Actions to perform if the condition is True.
<Action if condition is True>:
Action to perform if the condition is True.
<ELSE>:
Actions to perform if the condition is False (optional).
<Action if condition false>:
Action to perform if the condition is False (optional).
<END>:
Marks the end of the statement block.

Syntax 4 隐藏详细信息

 如果 <Condition 1> THEN
  <Action if condition 1 is True>
[ELSE IF <Condition 2> THEN
  <Action if condition 2 is True>
[ELSE IF <Condition 3> THEN
  <Action if condition 3 is True>
[...]]]
END

<IF>:
Marks the beginning of the statement block.
<Condition 1>:
1st condition to check.
<THEN>:
Actions to perform if the previous condition is True.
<Action if condition 1 is True>:
Action to perform if the 1st condition is True.
<ELSE IF>:
Checks the next condition if the previous condition is False (optional).
<Condition 2>:
2nd condition to check (optional).
<Action if condition 2 is True>:
Action to perform if the 2nd condition is True and if the 1st condition is False (optional).
<Condition 3>:
3rd condition to check.
<Action if condition 3 is True>:
Action to perform if the 3rd condition is True and if the 1st and 2nd conditions are False.
<END>:
Marks the end of the statement block.

注意

Single-line conditional statement

You also have the ability to use the following syntax:

<Result> = <Condition>? <Expression 1> ELSE <Expression 2>

Detailed syntax:

<Result>Variable to assign with the result of the condition.
<Condition>Condition to check.
<Expression 1>Value assigned to <Result> if the condition is True.
<Expression 2>Value assigned to <Result> if the condition is False.

Equivalence:

IF <Condition> THEN
<Result> = <Expression 1>
ELSE
<Result> = <Expression 2>
END

Note: The single-line conditional expression can be directly used in an expression.

Example: Increment the number of persons when the age is greater than 60, otherwise the number of persons remains the same.

ElderlyCustomer.CalculatedAge大于60Elderly+1否则Elderly

Condition

<Condition> can take the following format:

  • <Value> = <Expression>
Equality test
  • <Value> < <Expression>
Comparison test
  • <Value> <= <Expression>
Comparison test
  • <Value> > <Expression>
Comparison test
  • <Value> >= <Expression>
Comparison test
  • <Value> = <Minimum Expression> TO <Maximum Expression>
<Value> must be included between the minimum expression and the maximum expression
  • <Minimum Expression> <= <Value> <= <Maximum Expression>
  • <Value> 存在于 (<Expression1>, <Expression2>, ..., <Expression N>)
<Value> is compared to the result of a list of expressions. All the expressions found in the list are evaluated. The operator returns True if <Value> is equal to at least one of the expressions, False if <Value> is equal to none of the expressions.
  • <Value> 最优存在于 (<Expression1>, <Expression2>, ..., <Expression N>)
<Value> is compared to the result of a list of expressions. The expressions are evaluated from left to right. As soon as an expression is equal to <Value>, the remaining expressions are not evaluated and the operator returns True. If <Value> is equal to no expression, the operator returns False.

Composite condition

The 并且 and 或者 keywords are used to perform logical operations and to create composite conditions.

For example:

如果Customer.City"Montpellier"并且Customer.Title"Mr",那么
ManMontpellier++// Number of men living in Montpellier
结束

如果Customer.City"Montpellier"或者Customer.City"Lyon",那么
MontpellierLyon++// Number of customers living in Montpellier or in Lyon
结束

The conditions made of 并且 and 或者 are entirely evaluated.

For example:

A > 10 AND B < 20

Even if the first condition (A > 10) is false, the second condition (B < 20) will be checked.

Optimizing the evaluation of composite conditions: Use the _AND_ and _OR_ keywords. If the first condition is false (A>10 in our example), the second condition (B<20 in our example) will not be checked. See Logical operators for more details.