|
|
|
|
|
|
|
|
|
|
|
|
while
|
|
|
The while loop executes as long as an < expression > evaluates as true. This is the same as in any other programming language. |
|
|
|
|
|
There are two forms of while statement |
|
|
|
|
|
|
|
|
|
|
|
Syntax : while |
|
|
|
|
|
while (condition) statement
|
|
|
|
|
|
|
|
|
Syntax : do while |
|
|
|
|
|
do {
statement
} while (condition);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Example : do-while
|
|
|
|
|
|
1 program while_statement {
2 integer i = 0;
3 integer j = 10;
4 // while example
5 while (i < 5) {
6 printf("Value of i %0d\n",i);
7 i ++;
8 }
9 // do - while example
10 do {
11 printf("Value of j %0d\n", j);
12 j --;
13 } while (j > 5);
14 }
You could download file while_statement.vr here
|
|
|
|
|
|
Simulation : do-while
|
|
|
|
|
|
Value of i 0
Value of i 1
Value of i 2
Value of i 3
Value of i 4
Value of j 10
Value of j 9
Value of j 8
Value of j 7
Value of j 6
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|