使用右上角的选项卡切换到不同的编程语言。

使用右上角的选项卡切换到不同的编程语言。

使用右上角的选项卡切换到不同的编程语言。

使用右上角的选项卡切换到不同的编程语言。

whilewhileWhileWhilewhile While循环(算子)

名称

whilewhileWhileWhilewhile — 启动一个循环块,只要条件为真,就执行该循环块。

签名

while( : : Condition : )

Herror while(const Hlong Condition)

Herror T_while(const Htuple Condition)

void While(const HTuple& Condition)

static void HOperatorSet.While(HTuple condition)

def while(condition: int) -> None

描述

只要 ConditionConditionConditionConditionconditioncondition 参数评估结果为 'true'"true""true""true""true""true"(或非 0 值),whilewhileWhileWhileWhilewhile 语句将执行循环体直至对应的 endwhileendwhileEndwhileEndwhileEndwhileendwhile 语句。

若条件评估结果为 'false'"false""false""false""false""false"0),程序将跳过对应的 endwhileendwhileEndwhileEndwhileEndwhileendwhile 语句继续执行后续代码。

参数

ConditionConditionConditionConditionconditioncondition (输入控制)  integer HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)

循环条件。

示例(HDevelop)

dev_update_window ('off')
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowID)
read_image (Image, 'particle')
dev_display (Image)
stop ()
threshold (Image, Large, 110, 255)
dilation_circle (Large, LargeDilation, 7.5)
dev_display (Image)
dev_set_draw ('margin')
dev_set_line_width (3)
dev_set_color ('green')
dev_display (LargeDilation)
dev_set_draw ('fill')
stop ()
complement (LargeDilation, NotLarge)
reduce_domain (Image, NotLarge, ParticlesRed)
mean_image (ParticlesRed, Mean, 31, 31)
dyn_threshold (ParticlesRed, Mean, SmallRaw, 3, 'light')
opening_circle (SmallRaw, Small, 2.5)
connection (Small, SmallConnection)
dev_display (Image)
dev_set_colored (12)
dev_display (SmallConnection)
stop ()
dev_set_color ('green')
dev_display (Image)
dev_display (SmallConnection)
Button := 1
while (Button == 1)
  dev_set_color ('green')
  get_mbutton (WindowID, Row, Column, Button)
  dev_display (Image)
  dev_display (SmallConnection)
  dev_set_color ('red')
  select_region_point (SmallConnection, SmallSingle, Row, Column)
  dev_display (SmallSingle)
  NumSingle := |SmallSingle|
  if (NumSingle == 1)
    intensity (SmallSingle, Image, MeanGray, DeviationGray)
    area_center (SmallSingle, Area, Row, Column)
    dev_set_color ('yellow')
    set_tposition (WindowID, Row, Column)
    write_string (WindowID, 'Area='+Area+', Int='+MeanGray)
  endif
endwhile
dev_set_line_width (1)
dev_update_window ('on')

结果

如果指定参数的值正确,whilewhileWhileWhileWhilewhile(作为算子)返回 2 ( H_MSG_TRUE )。否则,将抛出一个异常并返回错误代码。

替代

forforForForForfor, untiluntilUntilUntilUntiluntil

另见

repeatrepeatRepeatRepeatRepeatrepeat, breakbreakBreakBreakBreakbreak, continuecontinueContinueContinueContinuecontinue, ififIfIfIfif, elseifelseifElseifElseifElseifelseif, elseelseElseElseElseelse

模块

基础