blog

SEAN K.H. LIAO

short circuit

Sometimes you are handed the hammer that is && and ||, and no proper if/else.

if...else

if x:
  a
else:
  b
(x && (a || true)) || b

if...else if...else

if x:
  a
else if y:
  b
else:
  c
(x && (a || true)) || (y && (b || true)) || c

nested if

if x:
  if y:
    a
  else:
    b
else:
  b
(x && (y && (a || true) || (b || true))) || c