title: Why is there a difference in Output when using Event Control Statement and Wait statement for the following simple D Flipflop example
body: <p>I have created a testbench for a simple positive edge trigerred d flip flop with synchronous active low reset. In the testbench, the first case gives inputs at "@posedge clk" and in the second case i am giving inputs based on "wait 10ns" statements.</p>
  
  <p>In the first case the output of the flop changes after 1 clock cycle, whereas in the second case it changes immediately in the same clock cycle in the simulator. </p>
  
  <p>I am simulating in Quartus Simulator.</p>
  
  <p>Why ? Thats what i wanted to know.</p>
  
  <p>Code as below:
  ////////////////////////////</p>
  
  <pre><code>initial
  begin
      //Case 1: Using Event Based statements
      n_reset = 1'b0;
      reset = 1'b1;
      d = 1'b0;
      repeat(2)@(posedge clk);
      n_reset = 1'b1;
      repeat(2)@(posedge clk);
      d = 1'b1;
      @(posedge clk);
      d = 1'b0;
      @(posedge clk);
      d = 1'b1;
  
      //Case 2: Using wait Statement
      #50ns;
      n_reset = 1'b0;
      reset = 1'b1;
      d = 1'b0;
      #50ns;
      n_reset = 1'b1;
      #20ns;
      d = 1'b1;
      #10ns;
      d = 1'b0;
      #10ns;
      d = 1'b1;
      #50ns;
  
  end
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/bdIYp.png" rel="nofollow">Waveform of D FlipFlop with the testbench</a></p>