What is the final decimal value stored in count after the following loop…
What is the final decimal value stored in count after the following loop completes? reg [3:0] count; integer i; initial begin count = 4'd0; for (i = 0; i < 4; i = i + 1) begin count = count + i; end end
- 0
- 6
- 10
- 15
Correct answer
B. 6
Explanation
The loop iterates 4 times with values of i ranging from 0 to 3: * $i = 0$: count = 0 + 0 = 0 * $i = 1$: count = 0 + 1 = 1 * $i = 2$: count = 1 + 2 = 3 * $i = 3$: count = 3 + 3 = 6 When $i = 4$, the condition $i < 4$ fails and the loop exits with count = 6 .