본문 바로가기
Language/Verilog & SV

[System Verilog] 'break' and 'continue'

by VIR&US 2023. 7. 19.
반응형

목차

break

loop construct에서 break를 만나면 바로 end로 진입합니다.

 

Code

module tb;	
	initial begin
     	// This for loop increments i from 0 to 9 and exit
    		for (int i = 0 ; i < 10; i++) begin
        		$display ("Iteration [%0d]", i);
        		if (i == 7)begin
          			break;
        		end
      		end
    	end
endmodule

Sim

ncsim> run
Iteration [0]
Iteration [1]
Iteration [2]
Iteration [3]
Iteration [4]
Iteration [5]
Iteration [6]
Iteration [7]
ncsim: *W,RNQUIE: Simulation is complete.

continue

loop construct에서 continue를 만나면 하단의 작업을 완료하지 않고 다시 loop construct로 진입합니다.

 

Code

module tb;
	initial begin
      	// This for loop increments i from 0 to 9 and exit
		for (int i = 0 ; i < 10; i++) begin
		        if (i == 7) begin
          			continue;
			end
        		$display ("Iteration [%0d]", i);
      		end
    	end
endmodule

Sim

ncsim> run
Iteration [0]
Iteration [1]
Iteration [2]
Iteration [3]
Iteration [4]
Iteration [5]
Iteration [6]
Iteration [8]
Iteration [9]
ncsim: *W,RNQUIE: Simulation is complete.
728x90
반응형

'Language > Verilog & SV' 카테고리의 다른 글

[Verilog] Blocking(=) vs Nonblocking(<=)  (0) 2023.07.19
[Verilog] Parameter  (0) 2023.07.19
[Verilog] D F/F  (0) 2023.07.19
[Verilog] Ram Model example Code  (0) 2023.07.06
[Verilog] LHS, RHS  (0) 2023.07.02