With the following enum definition in Solidity code...
enum Direction { North, South, East, West }
... I would like to set up a for-loop that iterates over this enum's values, e.g.
for (uint8 dirn = 0; dirn < xxx; dirn++) { ... }
Is there a way for the code to check what the size of the enum is, i.e. what should replace xxx
, other than the hard-coded literal value 4
?
values()
that returns an array of all the enum constants, and each enum has a methodname()
andordinal()
. That is perhaps useful when the enum is defined in a 3rd-party jar. I guess that would not be a relevant use case in Ethereum. Or could it be useful when using libraries (i.e. EthPM packages)? I do not have an actual use case. I was just trying to expand my knowledge of Solidity.