Procedural Constructs
return Statement
Returns a value to the caller from a function or exec block.
Syntax:
return expression ;
- expression : An optional value to be returned to the caller.
repeat Statement
Executes procedural_stmt repeatedly for the specified number of iteration. Syntax:
repeat (index_identifier : expression) procedural_stmt
- index_identifier : An optional index-variable identifier can be specified that ranges from
0to*iteration* - 1. It is read-only: the loop body must not change it (stated explicitly since PSS 3.1). - expression : Specifies iteration by a non-negative integer (e.g.,
intorbit). - procedural_stmt : Iterated by the number of iteration. Not executed if iteration is
0.
repeat-while Statement
Executes procedural_stmt repeatedly as long as the expression is true. Syntax:
repeat procedural_stmt while (expression);
- procedural_stmt : Iterated so long as the expression is true.
- expression : Evaluates true or false every time after procedural_stmt.
while Statement
Executes procedural_stmt repeatedly as long as the expression is true. Syntax:
while (expression) procedural_stmt
- procedural_stmt : Iterated so long as the expression is true.
- expression : Evaluates true or false every time before procedural_stmt.
foreach Statement
Executes procedural_stmt for each element of the expression. Syntax:
foreach (iterator_identifier : expression [index_identifier]) procedural_stmt
- iterator_identifier : An optional iterator-variable identifier with the collection element type, and is an alias of the current element.
- index_identifier : An optional index-variable identifier can be specified that ranges from
0tosize() - 1when expression isarray-type orlist-type, or over all keys when expression ismap-type. - expression : A collection type (e.g.,
array,list,map, orset). - procedural_stmt : Iterated for the number of
size()of the expression.
Warning
- For
set-type, index_identifier should NOT be specified. - At least one of iterator_identifier or index_identifier should be specified.
- Both iterator_identifier and index_identifier should NOT be changed inside procedural_stmt.
Note
- A colon (
:) must be appended after iterator_identifier if it is specified. - A pair of square brackets (
[]) must be used to contain index_identifier if it is specified. - The order of keys is undetermined when expression is
map-type.
Recipe: Iterate over a literal sequence
if-else Statement
Executes procedural_stmt_for_true when expression is true. Syntax:
if (expression) procedural_stmt_for_true else procedural_stmt_for_false
- expression : Evaluates true or false.
- procedural_stmt_for_true : Executed when the expression is true.
- procedural_stmt_for_false : An optional procedural statement that will be executed when the expression is false.
match Statement
Warning
There is no match form in a constraint block (LRM B.14). For a conditional constraint, use
if-else or an implication (->).
Executes procedural_stmt when the corresponding range matches the expression. Syntax:
match (expression) {
[range] : procedural_stmt
[range] : procedural_stmt
...
default : procedural_stmt
}
- expression : The item to be evaluated.
- range : An open range list is compared to the expression.
- procedural_stmt : Executed when expression matches any one in the corresponding range.
- default : An optional procedural statement that will be executed when no range was matched.
Warning
- Only one of ranges should be matched.
- The
defaultis executed if no range was matched. If no range was matched anddefaultis not provided, it is an error.
break Statement
Continues execution after the enclosing innermost loop construct. Syntax:
break;
Warning
The break statement may only appear within loop statements (repeat, repeat-while, while, or foreach) (LRM 20.7.11), so it cannot be used in a constraint or activity block.
continue Statement
Continues with the next loop iteration. Syntax:
continue;
Warning
The continue statement may only appear within loop statements (repeat, repeat-while, while, or foreach) (LRM 20.7.11), so it cannot be used in a constraint or activity block.
randomize Statement
Randomizes the specified data attributes or variables.
Syntax:
randomize variable, .., variable with constraints
- variable: A set of variables of plain-data type to be randomized together.
- constraints: Optional constraint rules.