Syntax: forever statement
The forever loop executes continuously until the end of a simulation is requested by a $finish. It can be thought of as a while loop whose condition is never false. The forever loop must be used with a timing control to limit its execution, otherwise its statement would be executed continuously at the expense of the rest of the design. The use of a forever loop is shown below.
reg clock; initial begin clock = 1'b0; forever #5 clock = ~clock; // the clock flips every 5 time units. end initial #2000 $finish;
EXERCISE
What is the problem with the following loop
reg clock; initial begin clock = 1'b0; #5 forever clock = ~clock; // the clock flips every 5 time units. end initial #2000 $finish;