# Conditional Statement in 'repeat loop'

**URL:** <https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342>\
**Category:** SystemVerilog\
**Tags:** transition-coverage-cross-bins-ignore\_bins, Coverage-bins, SystemVerilog, Coverage, systemverilog-Arrays-logics, uvm-packed-unpacked-array-SV\
**Created:** [May 2, 2022, 7:10pm UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342 "2022-05-02T19:10:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ShashankGurijala](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@ShashankGurijala](https://verificationacademy.com/forums/u/ShashankGurijala)\
**Post date:** [May 2, 2022, 7:10pm UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/1 "2022-05-02T19:10:36Z")

</div>

Hello!  
Here is a sample code to verify the transitional bins. I’ve repeated the loop randomly for 100000 times for functional coverage to become 100%.  
Now I want to add a condition in the repeat loop that at coverage = 100%, the block has to terminate. What changes should I make to the code?

```verilog
module transition_bins;

	bit [3:0] data;
	
	covergroup cg;
	
		c1: coverpoint data { 
		
				      bins d1[] = (9 => 3);
								
		         	      bins d2[] = (4 => 8 => 12);
							  
				      bins d3[] = (2,3 => 4,5); 
							  
	 		              bins d4[] = (2,3,4 => 5,6,7); 
							  
				      bins d5[] = (4'hd[*2] => 5,6,7);
							  
				      bins d6[] = (7[*2:4]); 
				  
				      bins d7 = (9 => 5[->3] => 11);

				      bins d8 = (12 => 15[=3] => 10);
		
				      }
							
							
	endgroup: cg
	
	initial 
	
		begin
		
			cg c = new;
			
			repeat (100000) //what should I change so that when the coverage is 100%, the repeat block terminates?
			
				begin
				
					data = $random;
					
					$display("\ndata = %0h",data);
					
					c.sample();
					
				end
				
			$display("\nCoverage = %0.4f%%",c.get_inst_coverage());
			
		end
		
endmodule

```

Thankyou!

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [May 2, 2022, 8:25pm UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/2 "2022-05-02T20:25:13Z")

</div>

_In reply to [Shashank Gurijala](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342):_

See the **break** statement.

---

<div class="post-metadata">

**Author:** ![graeme\_jessiman](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/graeme_jessiman/32/1201_2.png) [@graeme\_jessiman](https://verificationacademy.com/forums/u/graeme_jessiman)\
**Post date:** [May 2, 2022, 9:32pm UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/3 "2022-05-02T21:32:49Z")

</div>

_In reply to [Shashank Gurijala](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/2):_

you can do something like this:

```
   if (c.c1.get_coverage()==100.0)
   begin    
       $display("Total coverage = %6.2f", c.c1.get_coverage());
       $finish();
   end

```

---

<div class="post-metadata">

**Author:** ![rag123](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@rag123](https://verificationacademy.com/forums/u/rag123)\
**Post date:** [May 3, 2022, 12:20am UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/4 "2022-05-03T00:20:54Z")

</div>

_In reply to [Shashank Gurijala](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/3):_

```verilog

// Code your testbench here
// or browse Examples
module transition_bins;
 bit [3:0] data;
 covergroup cg;
 c1: coverpoint data { 
 
				      bins d1[] = (9 => 3);
 
		         	      bins d2[] = (4 => 8 => 12);
 
				      bins d3[] = (2,3 => 4,5); 
 
	 		              bins d4[] = (2,3,4 => 5,6,7); 
 
				      bins d5[] = (4'hd[*2] => 5,6,7);
 
				      bins d6[] = (7[*2:4]); 
 
				      bins d7 = (9 => 5[->3] => 11);
 
				      bins d8 = (12 => 15[=3] => 10);
 
				      }
 
 
	endgroup: cg
 
	initial 
 
		begin
 
			cg c = new;
 
          repeat (100000) //what should I change so that when the coverage is 100%, the repeat block terminates?
 
				begin
 
					data = $random;
 
					$display("\ndata = %0h",data);
 
					c.sample();
               if (c.get_inst_coverage==100.00) break;

                   
                  
				end
 
			$display("\nCoverage = %0.4f%%",c.get_inst_coverage());
          
          
     end
 
endmodule

```

---

<div class="post-metadata">

**Author:** ![ShashankGurijala](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@ShashankGurijala](https://verificationacademy.com/forums/u/ShashankGurijala)\
**Post date:** [May 3, 2022, 1:35am UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/5 "2022-05-03T01:35:59Z")

</div>

_In reply to [rag123](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/4):_

Yeah i did the same using if loop you tried. But I want to repeat the block exactly until coverage is 100% without mentioning any integer in the repeat block.

---

<div class="post-metadata">

**Author:** ![rag123](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/r/eada6e/32.png) [@rag123](https://verificationacademy.com/forums/u/rag123)\
**Post date:** [May 3, 2022, 1:53am UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/6 "2022-05-03T01:53:34Z")

</div>

_In reply to [Shashank Gurijala](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/5):_

```verilog

// Code your testbench here
// or browse Examples
module transition_bins;
 bit [3:0] data;
 covergroup cg;
 c1: coverpoint data { 
 
				      bins d1[] = (9 => 3);
 
		         	      bins d2[] = (4 => 8 => 12);
 
				      bins d3[] = (2,3 => 4,5); 
 
	 		              bins d4[] = (2,3,4 => 5,6,7); 
 
				      bins d5[] = (4'hd[*2] => 5,6,7);
 
				      bins d6[] = (7[*2:4]); 
 
				      bins d7 = (9 => 5[->3] => 11);
 
				      bins d8 = (12 => 15[=3] => 10);
 
				      }
 
 
	endgroup: cg
 
	initial 
 
		begin
 
			cg c = new;
 
          while (c.get_inst_coverage!=100.00) //what should I change so that when the coverage is 100%, the repeat block terminates?
 
				begin
 
					data = $random;
 
					$display("\ndata = %0h",data);
 
					c.sample();
             
 
 
 
				end
 
			$display("\nCoverage = %0.4f%%",c.get_inst_coverage());
 
 
     end
 
endmodule

```

---

<div class="post-metadata">

**Author:** ![ShashankGurijala](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@ShashankGurijala](https://verificationacademy.com/forums/u/ShashankGurijala)\
**Post date:** [May 3, 2022, 2:06am UTC](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/7 "2022-05-03T02:06:27Z")

</div>

_In reply to [rag123](https://verificationacademy.com/forums/t/conditional-statement-in-repeat-loop/40342/6):_

I tried using the forever loop and if loop inside and then break it. But I want to know if its possible to do it in repeat loop.

And using while is another idea, too. Thanks!
