View Single Post
Old 02-01-2021, 10:12 AM   #30
Quoth
Still reading
Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.Quoth ought to be getting tired of karma fortunes by now.
 
Quoth's Avatar
 
Posts: 14,164
Karma: 105212035
Join Date: Jun 2017
Location: Ireland
Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper
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.
Quoth is offline   Reply With Quote