Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of forever and always statements

Tags:

verilog

Both the following codes generate a clock. I need to know if there is any use of forever loop other than clock generation? I have only come across forever in clock generation. If it only serves this purpose, isn't it useless?

initial begin
clk = 0;
forever begin
#5 clk = ~clk;
end
end

initial begin
clk = 0 ;
always begin 
# 5 clk = ~clk;
end
end
like image 590
chitranna Avatar asked Apr 10 '13 23:04

chitranna


People also ask

What is the difference between always and Forever?

The main difference between always and forever is that always usually means at all times or on all occasions whereas forever usually means for an endless time. 1. Meaning and Usage of Always

Is it legal to write initial forever or Always Forever?

forever is a procedural statement that can only be used in a procedural context. So it is legal to write initial forever or always forever, but not just forever. The situation where forever becomes quite important is within tasks, which are procedural contexts, so use of always is not allowed.

Do you use “always” and “never” statements sparingly?

Most of us use “Always” and “Never” statements rhetorically - it’s also wise to use them sparingly, lest our own credibility be called into question. “Always” and “Never” statements are popular delivery vehicles of FOG - Fear, Obligation and Guilt.

What is an example of Forever in a sentence?

This meaning is similar to always and forever can be replaced by always in sentences that carry this meaning. For example, He is forever asking questions. = He is always asking questions. We’ve been waiting forever.


1 Answers

Your second code snippet is actually a syntax error. The difference between forever and always is that always can exist as a "module item", which is the name that the Verilog spec gives to constructs that may be written directly within a module, not contained within some other construct. initial is also a module item. always blocks are repeated, whereas initial blocks are run once at the start of the simulation.

forever is a procedural statement that can only be used in a procedural context. So it is legal to write initial forever or always forever, but not just forever.

The situation where forever becomes quite important is within tasks, which are procedural contexts, so use of always is not allowed. (Functions are procedural contexts as well, but may not contain delays, which makes it unlikely that forever will come in useful.

like image 190
Andy Avatar answered Sep 22 '22 00:09

Andy