This page is a shooting range: we list every kind of enum situation C can throw at you, then knock each one down with a fully worked example. If you have not yet seen how enums count, read the parent first: Enumerations.
Before we start, one promise from that parent note we will lean on constantly:
Everything below is this rule applied to trickier and trickier inputs.
Think of every enum you will ever meet as landing in one of these cells. Our job is to hit all of them.
#
Case class
What makes it tricky
Hit by
A
Pure defaults
plain 0,1,2,… counting
Ex 1
B
Explicit start, then resume
+1 rule continues from any number
Ex 2
C
Negative explicit value
counting still means +1, from below zero
Ex 3
D
Duplicate values
two names, one integer — legal
Ex 4
E
Zero / empty-ish & sentinel
trailing COUNT sizing an array
Ex 5
F
Out-of-range assignment
enum c = 99; — the "no type safety" edge
Ex 6
G
Real-world word problem
choosing enum vs magic numbers
Ex 7
H
Exam twist — mixed = and gaps
trace the whole chain by hand
Ex 8
Cells A–H below are each labelled. Together they cover defaults, explicit, resumed, negative, duplicate, zero/sentinel, degenerate/out-of-range, real-world, and exam-style — no scenario left uncovered.
The figure below shows the mental model we use everywhere: named sticky-notes on a number line.