DMI5.2 高级编程DO循环(有限循环)

899 篇文章 77 订阅
717 篇文章 27 订阅

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.
 

例子

  1.   下面的例子将提示语句循环执行4次,每次提示循环到第几遍
    
DO/KNPTN1,1,4,1

$$将数字转化为字符并与提示合并

KNPTC1=ASSIGN/CONCAT('这是第',STR(KNPTN1),'遍循环')

TEXT/OPER, KNPTC1

ENDDO
  1.   下面的程序控制机器在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

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

山涧果子

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值