DMIS 5.2高级编程之条件跳转(IF语句)

条件跳转

如果想改变程序的运行方向就要使用跳转语句,在DMIS里有几种命令可实现有条件的跳转,条件跳转就是必须满足给定的条件程序才能跳转。

IF…ENDIF程序块

IF语句以IF开头,ENDIF结尾,它可以使程序在满足规定的逻辑条件下跳转到其他行。逻辑条件由已定义的变量、算法或逻辑表达式组成。IF语句允许嵌套,语句格式如下:

IF/(表达式)

$$ DMIS程序

ENDIF

 

表达式:已定义的变量、算法或逻辑表达式
DMIS 5.2高级编程之条件跳转(IF语句)
DMIS 5.2高级编程之条件跳转(IF语句)
DMIS 5.2高级编程之条件跳转(IF语句)

DMIS 5.2标准:

Function:
 Transfers the control of the program based upon the conditional execution of a logical expression.  The expression can be comprised of previously defined variables, arithmetic expressions, or logical expressions.  Nested IF…ENDIF blocks are also supported.
  
 
Input Formats:
  
  
 
can be:
 IF/(var_1)
  
 
Output Formats:
  
  
 
can be:
 None
  
 
Synopsis:
 IF/(var_1)
executable statement(s)
ELSE
executable statement(s)
ENDIF
 
Where:
  
  
 
var_1 can be:

or:

or:
 varname 
var_2 var_3 var_2 
.NOT.  var_2
  
 
var_2 can be:

or:

or:

or:
 var_1 
varname 
value 
expr
  
 
var_3 can be:

or:

or:

or:

or:

or:

or:

or:
 .GT.  
.GE.  
.EQ.  
.LT.  
.LE.
.NE.  
.AND.  
.OR.
  
 
.AND.
 signifies the logical operator meaning and.
  
 
.EQ.
 signifies the relational operator meaning equal to.
  
 
.GE.
 signifies the relational operator meaning greater than or equal to.
  
 
.GT.
 signifies the relational operator meaning greater than.
  
 
.LE.
 signifies the relational operator meaning less than or equal to.
  
 
.LT.
 signifies the relational operator meaning less than.
  
 
.NE.
 signifies the relational operator meaning not equal to.
  
 
.NOT.
 signifies the logical operator meaning exclusion.
  
 
.OR.
 signifies the logical operator meaning or.
  
 
expr
 is an arithmetic expression.
  
 
value
 is any numeric value.
  
 
varname
 is any previously declared and assigned variable.
  
 
A logical IF must begin with an IF and end with an ENDIF statement.  ELSE statements are optional; however, there may be several ELSE statements in a logical IF sequence when IF statements are nested.  When IF statements are nested, care should be exercised to include corresponding ENDIF statements for every IF statement.  JUMPTO statements can be used anywhere within a block IF to transfer control out of the block.
  
 
If the logical expression evaluates to .TRUE., control of the program is passed to the statement(s) following the IF statement and executed until an ELSE or ENDIF is encountered.  If the logical expression is .FALSE., control of the program is passed to the statements following the next occurrence of ELSE.  If an ENDIF is encountered before an ELSE, the conditional is ended.
 

例子

  1.   如果变量VarA的数值比VarB的大,就会弹出提示“A比B大”
    
DECL/LOCAL,DOUBLE,VarA,VarB

VarA=ASSIGN/2

VarB=ASSIGN/1

IF/(VarA.GT.VarB)

TEXT/OPER,'A比B大'

ENDIF
  1.   下面的程序模拟登陆过程,密码正确提示可以登陆,错误的话要重新输入密码
    
(LOGIN)

KNPTN1 = PROMPT/TITLE,'登录',TEXT,'姓名:',EDIT,KNPTC1,TEXT,'密码:',EDIT,KNPTC2

IF/(KNPTC1.EQ.'DAVE').AND.(KNPTC2.EQ.'1234')

   TEXT/OPER, '登录成功!'

ELSE

   TEXT/OPER, '姓名或密码错误,请重新输入!'

   JUMPTO/(LOGIN)

ENDIF
  1.   下面的的程序让坐标机沿S型路径走一个矩形区域,注意“AND”运算符的用法。
    
DECL/LOCAL,DOUBLE,XVAR,YVAR

(STARTGO)

GOTO/XVAR,YVAR,50

XVAR=ASSIGN/XVAR+100

IF/(XVAR.EQ.500)

XVAR=ASSIGN/0

YVAR=ASSIGN/YVAR+100

ENDIF

IF/((XVAR.LE.500).AND.(YVAR.LE.500))

JUMPTO/(STARTGO)

ENDIF

高级示例:

Example 1

DECL/GLOBAL,CHAR,l,AnsrYN

DECL/GLOBAL,REAL,AnsR,A,B

DECL/GLOBAL,BOOL,DME

DME=ASSIGN/.TRUE.

IF/(DME)

JUMPTO/(outif)

ENDIF

executable statements

IF/((AnsrYN .EQ. 'N').AND.(AnsR .GT. 0.1))

executable statements

ENDIF

executable statements

(outif)

F(label)=FEAT/POINT,CART,25.31,41.45,1.76,0.00,0.00,-1.00

executable statements

IF/(A .LE. B)

executable statements

ELSE

IF/(A .LT. 3.0)

executable statements

ELSE

JUMPTO/(endblk)

ENDIF

ENDIF

(endblk)

Example 2

DECL/GLOBAL,BOOL,bad

executable statements

JUMPTO/(new_probe)

(restart)

by-passed executable statements

(new_probe)

SNSLCT/S(next_probe)

(cylndr7)

F(CYL7)=FEAT/CYLNDR,INNER,CART,-1.00,1.00,0.0,0.00,0.00,1.00,0.375

MEAS/CYLNDR,F(CYL7),8

PTMEAS/CART,-1.188,1.00,-0.250,1.00,0.00,0.00

PTMEAS/CART,-0.813,1.00,-0.250,-1.00,0.00,0.00

PTMEAS/CART,-1.00,1.188,-0.250,0.00,1.00,0.00

PTMEAS/CART,-1.00,0.813,-0.250,0.00,-1.00,0.00

PTMEAS/CART,-1.188,1.00,-5.250,1.00,0.00,0.00

PTMEAS/CART,-0.813,1.00,-5.250,-1.00,0.00,0.00

PTMEAS/CART,-1.00,1.188,-5.250,0.00,1.00,0.00

PTMEAS/CART,-1.00,0.813,-5.250,0.00,-1.00,0.00

ENDMES

executable statements

IF/(bad)

JUMPTO/(cylndr7)

ENDIF

DMIS 5.2高级编程之条件跳转(IF语句)

上一篇:python三目运算符


下一篇:【ocp-12c】最新Oracle OCP-071考试题库(44题)