Appearance
While 
While控件用于控制循环,可以使用Break控件提前结束循环。
业务属性 
| 属性 | 含义 | 说明 | 输入限定 | 示例值 | 
|---|---|---|---|---|
| enable | 是否启用该控件,未启用时不编译 | 是否编译 | 选择值 | 启用 | 
| text | 与控件关联的文本 | 设计页控件显示 | 常量 | while | 
| expression | 判断表达式 | Lua判断表达式 | Lua脚本 | var1>var2 | 
判断表达式完全遵循Lua语言的语法,其中不等于、逻辑与、逻辑或和逻辑非分别用~=、and、or和not表示,在判断表达式中变量的表示无需使用#{}占位符,直接书写变量名即可。
当表达式值为假时结束循环。
lua
while ... do
--code
endwhile ... do
--code
end使用示例 
使用LuaScript控件定义一个数组r1,用于存放输出参数:
lua
local r1={}local r1={}
将入参body的属性currentValue和endValue分别当作循环变量和循环结束值,判断表达式输入:
body.currentValue<=body.endValue

使用TableInsert控件往r1数组插入循环变量值:
body.currentValue

使用LuaScript控件对循环变量值自增 1:
lua
body.currentValue=body.currentValue+1body.currentValue=body.currentValue+1
使用Return控件输出结果r1:
json
{"r1":"#{r1}"}{"r1":"#{r1}"}
使用curl请求接口:
$ curl http://localhost:6636/api/while -d "{\"currentValue\":0,\"endValue\":5}"$ curl http://localhost:6636/api/while -d "{\"currentValue\":0,\"endValue\":5}"接口返回:
json
{
    "resCode": "0",
    "resMsg": "success",
    "data": {
        "r1": [0,1,2,3,4,5]
    }
}{
    "resCode": "0",
    "resMsg": "success",
    "data": {
        "r1": [0,1,2,3,4,5]
    }
}当循环变量值自增到6时,条件表达式判断为假,循环结束。