|
|
|

|
|
|
|
|
|

|
|
 |
case
|
|
|
The case statement compares an expression to a series of cases and executes the statement or statement group associated with the first matching case: |
|
|

|
|
|
- case statement supports single or multiple statements.
- Group multiple statements using begin and end keywords.
|
|
|

|
|
|
Syntax: |
|
|

|
|
|
case (primary_expression)
{
case1_expression : statement
case2_expression : statement
...
caseN_expression : statement
default : statement
}
|
|
|

|
|
|
|
|
|

|
|
 |
Example : case
|
|
|

|
|
|
1 program case_statement {
2 do_case(0);
3 do_case(1);
4 do_case(2);
5 }
6
7 task do_case(bit [1:0] sel) {
8 case(sel) {
9 0 : printf("Nothing is selected\n");
10 1 : {
11 printf("something is selected\n");
12 printf("This is multi statment example\n");
13 }
14 default : {
15 printf("Default is selected\n");
16 }
17 } // case (sel)
18 }
You could download file case_statement.vr here
|
|
|

|
|
 |
Simulation : case
|
|
|

|
|
|
Nothing is selected
something is selected
This is multi statment example
Default is selected
|
|
|

|
|
|

|
|
|

|
|
|
|
|
|

|
|
|
|
|
|

|
|
Copyright © 1998-2025 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|