if/else for Logic
Why if/else inside always @(*) describes a multiplexer, and why every branch must assign the output.
Updated 2026-07-07
Inside a combinational always @(*) block, if/else describes hardware selection — think MUX, not a program loop. An if with an else branch that between them assign every output on every input combination is exactly a 2-to-1 multiplexer: the select condition chooses which value reaches the output.
Every branch must assign the output. If a branch exists where the output is left unassigned — most commonly, an if with no matching else — the synthesizer infers a latch to hold the output's previous value whenever that branch is taken. The output is no longer purely combinational.
Combining if/else with a default-assignment-at-top gives two independent layers of protection: the default covers any path that falls through, and the else branch covers the one condition the if did not.