Tuesday, August 19, 2008

VHDL Part 23 : Exiting the Loops

There are also two ways with which the user can exit a loop.

(1) next

The next statement terminates the execution of a loop and jumps to another iteration if a condition is met. Shown below is the syntax.

-----------------------------------------------------------------------------------------
loop_label : for loop_indentifier in loop_range loop -- example: for i in 4 downto 0 loop

sequential_code

next when exit_condition; -- example: next when i = 1;

sequential_code

end loop loop_label;
-----------------------------------------------------------------------------------------

(2) exit

The exit statement, when a condition is satisfied, terminates the execution of whatever the loop is currently doing and terminates the loop itself. It does not jump to any other iteration. Shown below is the syntax.

-----------------------------------------------------------------------------------------
loop_label : for loop_indentifier in loop_range loop -- example: for i in 4 downto 0 loop

sequential_code

exit when exit_condition; -- example: exit when i = 1;

sequential_code

end loop loop_label;
-----------------------------------------------------------------------------------------

Reference:
(1) Pedroni, V., Circuit Design with VHDL, The MIT Press, 2004.

No comments: