《IF语句的使用.docx》由会员分享,可在线阅读,更多相关《IF语句的使用.docx(6页珍藏版)》请在三一办公上搜索。
1、IF语句的使用u *if,val1, oper, val2, base: 条件语句 val1, val2: 待比较的值 oper: 逻辑操作 eq, ne, lt, gt, le, ge, ablt, abgt base: 当oper结果为逻辑真时的行为 lable: 用户定义的行标志 stop: 将跳出anasys exit: 跳出当前的 do循环 cycle: 跳至当前do循环的末尾 then: 构成if-then-else结构 注意:不允许跳出、跳进一个do,if循环至label句 ? *IF, VAL1, Oper1, VAL2, Base1, VAL3, Oper2, VAL4, B
2、ase2 Conditionally causes commands to be read. APDL: Process Controls MP ME ST PR PRN FL EM PP Argument Descriptions VAL1 First numerical value (or parameter which evaluates to a numerical value) in the conditional comparison operation. VAL1, VAL2, VAL3, and VAL4 can also be character strings (enclo
3、sed in quotes) or parameters for Oper = EQ and NE only. Oper1 Operation label. A tolerance of 1.0E-10 is used for comparisons between real numbers: EQ - Equal (for VAL1 = VAL2). NE - Not equal (for VAL1 VAL2). LT - Less than (for VAL1 VAL2). LE - Less than or equal (for VAL1 GE - VAL2). Greater than
4、 or equal (for VAL1 ABLT - VAL2). Absolute values of VAL1 and VAL2 before operation. VAL2 Second numerical value (or parameter which evaluates to a numerical value) in the conditional comparison operation. Base1 Action based on the logical expression (Oper1) being true. If false, continue reading at
5、 the next line. This is conditional, except for the IF-THEN-ELSE constructs described below; any of the following constructs (through Base1 = THEN) cause all subsequent fields to be ignored: :label - A user-defined label (beginning with a colon (:), 8 characters maximum). The command reader will ski
6、p (and wrap to the beginning of the file, if necessary) to the first line that begins with the matching :label. Caution This label option may not be mixed with do-loop or if-then-else constructs. STOP - This action will cause an exit from the ANSYS program at this line, unless running in interactive
7、 mode. In interactive mode, the program will not stop. EXIT - Exit the current do-loop *EXIT. CYCLE - Skip to the end of the current do-loop *CYCLE. THEN - Make this *IF an if-then-else construct (see below). The following optional values determine the connection between the two logical clauses Oper
8、1 and Oper2 AND - True if both clauses (Oper1 and Oper2) are true. OR - True if either clause is true. XOR - True if either (but not both) clause is true. VAL3 Third numerical value (or parameter which evaluates to a numerical value). Oper2 Operation label. This will have the same labels as Oper1, e
9、xcept it uses Val3 and Val4. A tolerance of 1.0E-10 is used for comparisons between real numbers. VAL4 Fourth numerical value (or parameter value which evaluates to a numerical value). Base2 Action based on the logical expression (Oper1 and Oper2) being true. They will be the same values as Base1, e
10、xcept as noted. Command Default Read commands sequentially. Notes Conditionally causes commands to be read from a specific block or at a specific location. Twenty levels of nested *IF blocks are allowed. Jumping to a :label line is not allowed with keyboard entry. Jumping into, out of, or within a d
11、o-loop or an if-then-else construct to a :label line is not allowed. The following is an example of an if-then-else construct: *IF,VAL1,Oper,VAL2,THEN - *ELSEIF,VAL1,Oper,VAL2 - *ELSEIF,VAL1,Oper,VAL2 - *ELSE - *ENDIF where - represents a block of any number of commands. Any number of *ELSEIF clause
12、s (or none) may be included (in the location shown). One *ELSE clause (at most) may be included (in the location shown). The *IF command is executed by evaluating its logical expression. If it is true, the block of commands following it is executed. The construct is considered to be complete and the
13、 command following the *ENDIF is executed next. If the logical expression is false, the next *ELSEIF command (if any) following the block is executed. The execution logic is the same as for *IF. The effect is that the logical expressions in the *IF and the *ELSEIF commands are sequentially tested un
14、til one is found to be true. Then the block of commands immediately following the expression is executed, which completes the execution of the if-then-else construct. If all *IF and *ELSEIF expressions are false, the block following the *ELSE command is executed, if there is one. Only one block of c
15、ommands (at most) is executed within the if-then-else construct. If a batch input stream hits an end-of-file during a false *IF condition, the ANSYS run will not terminate normally. You will need to terminate it externally (use either the UNIX “kill” function or the Windows task manager). The *IF, *ELSEIF , *ELSE, and *ENDIF commands for each if-then-else construct must all be read from the same file (or keyboard). This command is valid in any processor. Menu Paths