Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

do

do( 
( 
( 
s_var1 
g_initExp1 
[ g_stepExp1 ] 
)
( 
s_var2 
g_initExp2 
[ g_stepExp2 ] 
) ... 
)
( 
g_terminationExp 
g_terminationExp1 ... 
)
            g_loopExp1 
            g_loopExp2 ... 
)
=> g_value

Description

Iteratively executes one or more expressions. Used in SKILL++ mode only.

Use do to iteratively execute one or more expressions. The do expression provides a do-while facility allowing multiple loop variables with arbitrary variable initializations and step expressions. You can declare

A do Expression Evaluates in Two Phases

More formally stated:

  1. Each iteration begins by evaluating the termination condition.
    If the termination condition evaluates to a non-nil value, the do expression exits with a return value computed as follows:
  2. The termination expressions terminationExp1, terminationExp2, ... are evaluated in order. The value of the last termination condition is returned as the value of the do expression.
    Otherwise, the do expression continues with the next iteration as follows.
  3. The loop body expressions g_loopExp1, g_loopExp2, ... are evaluated in order.
  4. The step expressions g_stepExp1, g_stepExp2, ..., if given, are evaluated in an unspecified order.
  5. The local variables var1, var2, ... are bound to the above results. Reiterate from step one.

Value Returned

g_result

The value of the expression executed.

Examples

By definition, the sum of the integers 1, ..., N is the Nth triangular number. The following example finds the first triangular number greater than a given limit.

procedure( trTriangularNumber( limit )
do(
( ;;; start loop variables
( i 0 i+1 )
( sum 0 ) ;;; no step expression
;;; same as ( sum 0 sum )
) ;;; end loop variables
( sum > limit ;;; test
sum ;;; return result
)
sum = sum+i ;;; body
) ; do
) ; procedure
trTriangularNumber( 4 ) => 6
trTriangularNumber( 5 ) 
=> 6
trTriangularNumber( 6 ) 
=> 10

Related Topics

Flow Control Functions

while


Return to top
 ⠀
X