mercredi 12 août 2020

Using while true to avoid nested conditionals - "standard in complex selection"?

I recently came across the following pattern while reviewing someone's code:

while True:
   if not a.b:
      break

   if sum(b) > 1:
      x = a.c
      break
   break

I questioned the use of the while construct when not iterating anything. The answer from the coder was that this pattern avoids nested conditionals, and is a "standard pattern in complex selection."

Questions

  • Does this pattern have a name?
  • What exactly is "complex selection"?

Aucun commentaire:

Enregistrer un commentaire