5.5. Control Functions Quick Reference

The table below describes APDL commands that perform control functions within macros.

Most of the important information about these commands appears here, but you may want to look at the complete command descriptions in the Command Reference.

APDL Command Action It Takes Usage Tips
*DO Defines the start of a "do" loop. The commands following the *DO command execute (up to the *ENDDO command) repeatedly until some loop control is satisfied.
  • You can also control looping via the *IF command.

  • Mechanical APDL allows up to 20 levels of nested "do" loops, although "do" loops that include /INPUT, *USE, or an "unknown" command macro support fewer nesting levels because they do internal file switching.

  • *DO, *ENDDO, *CYCLE, and *EXIT commands in a "do" loop must all read from the same file or the keyboard.

  • Do not include picking operations in a "do" loop.

  • Be careful if you include a /CLEAR command within a do-loop. The /CLEAR command does not clear the do-loop stack, but it does clear all parameters including the loop parameter in the *DO statement itself. You can avoid the problem of having an undefined looping value by issuing a PARSAV command before the /CLEAR command, and then following the /CLEAR command with a PARRES command.

*ENDDO Ends a "do" loop and starts the looping action. You must use one *ENDDO command for each nested "do" loop. The *ENDDO and *DO commands for a loop must be on the same file.
*CYCLE When executing a "do" loop, Mechanical APDL bypasses all commands between the *CYCLE and *ENDDO commands, then (if applicable) initiates the next loop. You can use the cycle option conditionally (via the *IF command). The *CYCLE command must appear on the same file as the *DO command and must appear before the *ENDDO command.
*EXIT Exits from a "do" loop. The command following the *ENDDO command executes next. The *EXIT and *DO commands for a loop must be on the same file. You can use the exit option conditionally (via the *IF command).
*IF Causes commands to be read conditionally.
  • You can have up to 10 nested levels of *IF blocks.

  • You cannot jump into, out of, or within a "do" loop or an if-then-else construct to a :label line, and jumping to a :label line is not allowed with keyboard entry.

  • You can issue a /CLEAR command within an if-then-else construct. The /CLEAR command does not clear the *IF stack and the number of *IF levels is retained. An *ENDIF is necessary to close any branching logic.

  • The /CLEAR command deletes all parameters, including any that are used in your branching commands. You can avoid any problems that might arise from the deletion of parameters by issuing a PARSAV command before the /CLEAR command, and then following the /CLEAR command with a PARRES command.

*ENDIF Terminates an if-then-else construct. (See the *IF discussion for details.) The *IF and *ENDIF commands must appear in the same file.
*ELSE Creates a final, optional block separator within an if-then-else construct. (See the *IF discussion for details.) The *ELSE and *IF commands must appear in the same file.
*ELSEIF Creates an optional, intermediate block separator within an if-then-else construct. If Oper = EQ or NE, VAL1 and VAL2 can also be character strings (enclosed in quotes) or parameters. The *IF and *ELSEIF commands must be on the same file.