Previous

Exit Statements

The exit statement terminates a loop. Execution continues with the statement following the end loop. The syntax follows.

exit [ label ] [ when condition ] ;

An exit statement with no label terminates the innermost enclosing loop. When you identify a loop label, that named loop is terminated, as shown in the above example of a named next statement.

The optional when clause executes its exit statement when its condition (a Boolean expression) evaluates to TRUE.

The exit and next statements are equivalent constructs. Both statements use identical syntax, and both skip the remainder of the enclosing (or named) loop. The only difference between the two statements is that exit terminates its loop and, then, continues with the next loop iteration (if any).

The example below compares two bit vectors. An exit statement exits the comparison loop when a difference is found. The resulting circuit is shown in the figure following this example.

signal A, B:          BIT_VECTOR(1 downto 0);
signal A_LESS_THAN_B: Boolean;
. . .
A_LESS_THAN_B <= FALSE;
   
for I in 1 downto 0 loop
     if (A(I) = '1' and B(I) = '0') then
          A_LESS_THAN_B <= FALSE;
          exit;
     elsif (A(I) = '0' and B(I) = '1') then
          A_LESS_THAN_B <= TRUE;
          exit;
     else
          null;      -- Continue comparing
     end if;
end loop;

Figure 6.8 Circuit for Comparator Using the exit Statement

Next