quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif Loop Control

Like in Verilog, VERA supports breaking of loop or skip the execution inside the a part of code inside the loop. This is slightly different then what we are used in Verilog.

   

space.gif

  • continue : The continue statement forces the next iteration of a loop to take place, skipping any code in between.
  • break : The break statement is used to force the immediate termination of a loop, bypassing the normal loop test.
   

space.gif

In a repeat loop, the continue statement passes control back to the top of the loop. If the loop is complete, control is then passed to the first line of code after the loop.

   

space.gif

In a for loop, the continue statement causes the conditional test and increment portions of the loop to execute.

   

space.gif

In a while loop, the continue statement passes control to the conditional test.

   

space.gif

When the break statement is executed from inside a loop, the loop is immediately terminated and control passes to the first line of Vera code after the loop. If the break statement is executed outside of a loop, a syntax error is generated.

   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : Loop Control
   

space.gif


  1 program loop_control {
  2    integer i;
  3    // For loop continue
  4    printf("-----FOR LOOP CONTINUE---\n");
  5    for (i = 0 ; i < 3; i ++ ) {
  6      if (i == 1) continue;
  7      printf("Value of i is %0d\n",i);
  8    }
  9    // repeat loop continue
 10    i = 0;
 11    printf("-----REPEAT LOOP CONTINUE---\n");
 12    repeat (3) {
 13      i ++;
 14      if (i == 2)  {
 15        continue;
 16      }
 17      printf("Value of i is %0d\n",i);
 18    }
 19    // while loop continue
 20    printf("-----WHILE LOOP CONTINUE---\n");
 21    while (i > 0) {
 22      i --;
 23      if (i == 2)  {
 24        continue;
 25      }
 26      printf("Value of i is %0d\n",i);
 27    }
 28    // For loop break 
 29    printf("-----FOR LOOP BREAK---\n");
 30    for (i = 0 ; i < 3; i ++ ) {
 31      if (i == 1) break;
 32      printf("Value of i is %0d\n",i);
 33    }
 34    // repeat loop break
 35    i = 0;
 36    printf("-----REPEAT LOOP BREAK---\n");
 37    repeat (3) {
 38      i ++;
 39      if (i == 2)  {
 40        break;
 41      }
 42      printf("Value of i is %0d\n",i);
 43    }
 44    // while loop break
 45    i = 5;
 46    printf("-----WHILE LOOP BREAK---\n");
 47    while (i > 0) {
 48      i --;
 49      if (i == 2)  {
 50        break;
 51      }
 52      printf("Value of i is %0d\n",i);
 53    }
 54 }
You could download file loop_control.vr here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : Loop Control
   

space.gif

 -----FOR LOOP CONTINUE---
 Value of i is 0
 Value of i is 2
 -----REPEAT LOOP CONTINUE---
 Value of i is 1
 Value of i is 3
 -----WHILE LOOP CONTINUE---
 Value of i is 1
 Value of i is 0
 -----FOR LOOP BREAK---
 Value of i is 0
 -----REPEAT LOOP BREAK---
 Value of i is 1
 -----WHILE LOOP BREAK---
 Value of i is 4
 Value of i is 3
   

space.gif

   

space.gif

   

space.gif

   

space.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

  

Copyright © 1998-2014

Deepak Kumar Tala - All rights reserved

Do you have any Comment? mail me at:deepak@asic-world.com