PC SOFT

WINDEV的在线文档

  • Equivalent syntax
  • Code to run
  • Increment step
  • Exiting from a FOR loop
  • Running the next iteration
文档页面当前正在翻译。对于此延迟我们深表歉意。
您可以自愿地帮助我们翻译您想要的文档段落,然后只需通过以下地址与我们联系: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 block is repeated while a control variable is modified and compared to a limit value (before each beginning of the statement block).

The statement block is run for each one of the values successively taken by the control variable. The initial value is assigned to the control variable during the first entry in the 对于 statement.

An optimized syntax is available: this syntax prevents the end value and/or the step value from being re-evaluated at each iteration (useful for a loop on the number of table rows for example).

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.
例子
对于Subscript1直到10
MyArraySubscript】=MyVariable+10
结束

对于Subscript10直到1不-1
MyArraySubscript】=MyVariable+10
结束

对于Subscript1直到5
跟踪Subscript
结束
信息Subscript // Subscript is set to 6

// Optimized syntax
// Browse the table rows.
// The number of rows is calculated once only
对于Subscript1最优直到TABLE_MyTable..数目
COL_MyColSubscript】..颜色=打印.深绿色
结束

语法
 对于 <Control variable> = <Initial value> TO <Final value> [STEP <x>]
...
END

<FOR>:
Marks the beginning of the statement block.
<Control variable>:
Scalar simple variable (integer or real).

There is no need to declare this variable. Indeed, this variable is automatically declared.

<Initial value>:
Initial value of the control variable (integer or real).
<Final Value>:
Final value of the control variable (integer or real).
<NOT>:
Increment step (optional) of the control variable (1 by default).
<x>:
Optional value of the increment step (same type as the type of the control variable).
<END>:
Marks the end of the statement block.

Other possible syntaxes 隐藏详细信息

 对于 <Control Variable> = <Initial Value> _TO_ <Final Value> [STEP <x>]
...
END

FOR <Control Variable> = <Initial Value> _TO_ <Final Value> [_STEP_ <x>]
...
END

FOR <Control Variable> = <Initial Value> TO <Final Value> [_STEP_ <x>]
...
END

<_TO_>:
Signals that the final value must be evaluated once only
<_STEP_>:
Signals that the increment step must be evaluated once only.

注意

Equivalent syntax

You also have the ability to use the following syntax:

FOR <Control Variable> = <Initial Value> TO <Final Value> [STEP <x>]; ... ; END

The semicolon is used to separate the different lines.

Code to run

The code to run is located between the 对于 and 结束 statements.

Increment step

The increment step of the 对于 statement must be constant. A warning is displayed during the project compilation if the increment step is likely to change at each iteration.

Exiting from a FOR loop

Several statements are available:
  • 返回 statement: Exits from the 对于 loop and exits from the current process (or procedure).
  • 返回 statement: Return a status report to the calling process. Exits from the 对于 loop and exits from the current process (or procedure).
  • 跳出 statement/"跳出:" label: Exits the 对于 loop and run the rest of the current process.
关闭 is used to exit from the 对于 loop and to close the current window.

Caution: 返回 statement and 返回 statement cannot be used in the same process.

Running the next iteration

To directly run the next iteration without ending the code of the next iteration, use the 继续 statement / "继续:" label statement:

FOR <Control variable> = <Initial value> TO <Final value> [STEP <x>]
...
IF <Condition> THEN CONTINUE   // Return to the FOR keyword
...
END

In this case, the control variable is automatically incremented.