Oct-27-2019, 12:26 AM
Hello,
I have potentially eight sequential ifs I need to test for, so instead of nesting eight if statements I thought to use a while loop.
My goal is for the while loop to end once one of my functions returns a value greater than 0. Is there a better way to achieve this
than my method below?
x = 0
while x == 0:
x = function returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = 3
I have potentially eight sequential ifs I need to test for, so instead of nesting eight if statements I thought to use a while loop.
My goal is for the while loop to end once one of my functions returns a value greater than 0. Is there a better way to achieve this
than my method below?
x = 0
while x == 0:
x = function returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = function with different arguments returning 0, 1, or 2
if x > 0:
break
x = 3