Reputation: 13
I have a for loop like the following:
flag = True
for i in range(100000):
if flag:
foo()
else:
bar()
The flag variable is set by a command line argument and stays the same for every loop. Is there any way to get rid of the costly if statement, other than having 2 different for loops? Thanks in advance.
Upvotes: 1
Views: 878
Reputation: 6203
flag = True
func = foo if flag else bar
for i in range(100000):
func()
Upvotes: 1