DO循环
使用DO循环语句可以多次反复执行同一段程序,执行的次数可以是设定的数字、变量。
DO…ENDDO语句块
DO…ENDDO语句块以DO开头,ENDDO结尾,可以反复多次执行一组程序行,支持嵌套。格式如下:
DO/变量, 初始值, 结束值, 步长
$$ DMIS语句
ENDDO
变量:已定义的整数型变量
初始值:循环开始后变量开始计数的数值,为整数值
结束值:变量达到这个值后循环停止,为整数值
步长:变量每循环一次的增加值,可选项,不写默认为1
DMIS 5.2 标准如下:
Function:
provides the capability of repeating a sequence of instructions based on an initial and limit value at a specified increment.
Input Formats:
can be:
DO/index,initial,limit var_1
Output Formats:
can be:
None
Synopsis:
DO/index,initial,limit,increment
executable statement(s)
ENDDO
Where:
var_1 can be:
or:
,increment
does not exist
increment
is a positive integer representing the increment value. If omitted, the increment is 1.
index
is a positive integer representing the DO loop index variable. It is a variable previously declared with a DECL/INTGR statement.
initial
is a positive integer representing the initial value of the DO loop index variable.
limit
is a positive integer representing the limit value of the DO loop index variable.
The variables above must be an integer or integer variable. When DO loops are nested, care should be exercised to include the corresponding ENDDO statements for every DO statement.
例子
-
下面的例子将提示语句循环执行4次,每次提示循环到第几遍
DO/KNPTN1,1,4,1
$$将数字转化为字符并与提示合并
KNPTC1=ASSIGN/CONCAT('这是第',STR(KNPTN1),'遍循环')
TEXT/OPER, KNPTC1
ENDDO
-
下面的程序控制机器在500X500的范围内走S形轨迹
DECL/LOCAL,REAL,XPOS,YPOS
DECL/LOCAL,INTGR,XN,YN
DO/YN,0,500,100
$$RL函数将整数转换为实数
YPOS=ASSIGN/RL(YN)
DO/XN,0,500,100
XPOS=ASSIGN/RL(XN)
GOTO/XPOS,YPOS,50
ENDDO
ENDDO
高级示例:
An example of the use of the DO loop statement is as follows:
DECL/GLOBAL,INTGR,X_dim,A,I
DECL/GLOBAL,CHAR,10,featname
M(featdef)=MACRO/'dum_label',x,y,z
F(dum_label)=FEAT/CIRCLE,INNER,CART,x,y,z,0,0,1
ENDMAC
A=ASSIGN/3
X_dim=ASSIGN/18
$$
$$ To define circles aligned along the X direction
$$
DO/I,1,10,A
featname=ASSIGN/CONCAT('circ_',STR(I))
DO/X_dim,10,1,-1
CALL/M(featdef),featname,X_dim,2.0,0.0
ENDDO
ENDDO