top of page

14.5.2. Case Statements

​

The case statement provides a clean way to implement multi-way branching based on the value of an expression.

​

Unlike if-else ladders, case statements evaluate all branches in PARALLEL and select the matching branch.

​

Basic case Statement

​

Syntax

Verilog

Key Characteristics
 

  • Parallel evaluation (not sequential like if-else)
     

  • Only ONE branch executes (first match)
     

  • default is optional but HIGHLY recommended
     

  • Exact bit-by-bit comparison (X and Z compared)
     

  • Multiple values can map to same statement
     

Simple Examples

Verilog

Multiple Values for Same Branch

Verilog

14.5.2.1. casex and casez - Don't Care Matching
 

casez Statement

​

casez treats ? and Z as don't care bits in BOTH expression and case items.

Verilog

casex Statement
 

casex treats ?, X, and Z as don't care bits in BOTH expression and case items.

Verilog

Comparison: case vs casez vs casex

Screenshot (756).png

âš  WARNING: casex can mask X values from bugs! Use casez preferably, and case when possible.

14.5.2.2. Full Case and Parallel Case

Full Case

A case statement is FULL if all possible values of the expression are covered. If not full, unspecified values take default (or create latches).

Verilog

Parallel Case

​

A case statement is PARALLEL if no two case items can match simultaneously. If not parallel, priority is determined by order (first match wins).

Verilog

Comparison: If/Else vs Case

Screenshot (757).png

if else

Advanced
techniques

 

© Copyright 2025 VLSI Mentor. All Rights Reserved.©

Connect with us

  • Instagram
  • Facebook
  • Twitter
  • LinkedIn
  • YouTube
bottom of page