Quote:
if current_state == 0:
set_lights_green()
return
if current_state == 1:
set_lights_red()
return
set_lights_blue()
|
That sort of structure is for junk compilers, or pseudo code for assembler for some sort of very primitive microcontroller. Easy to get wrong too.
if then else is perfectly readable, more readable. Nested IFs can be perfectly readable.
For more options you want a select or case table or state machine. Admittedly some languages only allow a single test and then each option is indexed by a simple scalar type like an integer. But there are readable ways to have bigger IF chains and ways to preprocess the conditions.