Use of always block

can we use always block inside a if statement??

if (wxor_nic_axi_if_i.wvalid && wxor_nic_axi_if_i.wready && !mp_wr_data_512byte_bck2bck_one_go == 1'b1)
     begin
       always @ (posedge wxor_nic_axi_if_i.wlast)
         begin
           if (wxor_nic_axi_if_i.awlen == 4'hf)
             begin
               mp_wr_data_512byte_bck2bck_one_go_cnt++;
               $display("value of mp_wr_data_512byte_bck2bck_one_go_cnt is %0d",mp_wr_data_512byte_bck2bck_one_go_cnt);
               if(mp_wr_data_512byte_bck2bck_one_go_cnt == 3'b100)
               begin
                  mp_wr_data_512byte_bck2bck_one_go = 1'b1;
                  mp_wr_data_512byte_bck2bck_one_go_cg_obj.sample();
                  $display("mp_wr_data_512byte_bck2bck_one_go_cg is sampled");
               end
             end
           else 
             mp_wr_data_512byte_bck2bck_one_go_cnt = 3'b0;
         end
     end

end

No, but you can use a forever statement.

In reply to dave_59:

thanks dave,
can you please explain a bit why forever can be used but not always??
i was trying to write the above code in an interface.

regards,
samir

In reply to samir singh:

Here is slightly more than a bit of explanation:

A forever is a procedural looping statement, equivalent to a while (1) loop. You can enter a forever loop at any time in the procedural flow of your code. You can use the break statement along with a number of other constructs to get out a forever loop.

An always block is a declarative construct. It declares a procedural block of code as an independent process starting at time 0. When the procedural block of code finishes, the block repeats endlessly. There is no way to terminate the process started by an always block other than ending the simulation. An always block may only appear in the declarative section of a module or interface. You cannot put an always block inside a procedural block of code.

I was not entirely correct in my original answer about the if statement because there are many different kinds of if constructs in SystemVerilog. Your code fragment does not give enough context to determine which kind is being used.

There is the if construct that is a procedural conditional branching statement. You can put that if within any procedural block, and each branch is another procedural block. So you cannot put an always block inside a procedural branch of an if statement. I’m assuming this is the kind of if construct you intended.

There is also a declarative if-generate construct. This if-generate construct gets evaluated during compilation/elaboration, not at run time. Each branch of the if-generate can be another declarative block, which may contain an always block. See section 27.5 Conditional generate constructs in the LRM for more details.

In reply to dave_59:

thanks dave :)