quick.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

space2.gif

   

space.gif

   

space.gif

  ../images/main/bullet_green_ball.gif Introduction

Vera like any other programming language supports controlling of flow of program execution. Vera supports following constructs.

   

space.gif

  • if-else
  • case
  • repeat
  • for
  • while
  • foreach
   

space.gif

We will be seeing each of this in detail in next few pages.

   

space.gif

   

space.gif

  ../images/main/bulllet_4dots_orange.gif if-else

The if - else statement controls the execution of other statements. In programming language like Verilog, if - else controls the flow of program. When more than one statement needs to be executed for an if condition, then we need to use { and }.

   

space.gif

Syntax:

   

space.gif

 if (expression)
  {
    if_statement1;
    if_statement2;
    if_statementN;
  }
 else
  {
    else_statement1;
    else_statement2;
    else_statementN;
  }
   

space.gif

   

space.gif

  ../images/main/bullet_star_pink.gif Example : if-else
   

space.gif


  1 program if_else {
  2   integer i = 100;
  3   integer j = 10;
  4   // simple if with only one statement to execute
  5   if (i == 100)
  6     printf("value of i is 100\n");
  7   else
  8     printf("value of i is not 100\n");
  9 
 10   // if with muliple statements
 11   if (i > 60) {
 12     printf ("I is greater then 60\n");
 13     printf ("I value is %0d\n",i);
 14   } else {
 15     printf ("I is less then 60\n");
 16     printf ("I value is %0d\n",i);
 17   }
 18   // nested if 
 19   if (i > 100) {
 20     printf ("I is greater then 100\n");
 21   } else if (j > 5) {
 22     printf ("J is greater then 5\n");
 23   } else {
 24     printf ("I is not greater then 100\n");
 25     printf ("J is not greater then 5\n");
 26   }
 27 
 28 }
You could download file if_else.vr here
   

space.gif

  ../images/main/bullet_star_pink.gif Simulation : if-else
   

space.gif

 value of i is 100
 I is greater then 60
 I value is 100
 J is greater then 5
   

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