Take the 2-minute tour ×

Is there a way to reorder the execution of if statements using a for or while loop such that I could perform said statements in every permutation of their ordering? I want to maximize the result of a process regarding said if statements and figure out what ordering of if statements would do so.

share|improve this question
Do you have any code examples to show us? –  OakNinja Feb 11 '13 at 12:35
I haven't any clue how it would work. It would ideally execute a series of if statements that are of the same indentation level in all possible different orders. –  Jared Feb 11 '13 at 12:39
sure you could. For example, in python you could make each IF perform a function, then map that function to a list. Then generate every possible combination (itertools) of that list then execute and time each in turn till you find the fastest combination(s). –  Paul Collingwood Feb 11 '13 at 12:43
I was't looking for fastest, but this answers my question perfectly. I'm a complete programming noob, could you provide an ex of mapping the if statement to a list? –  Jared Feb 11 '13 at 12:45
x = [n==1,n==2,n==3,n==4] y = [1, 2, 3, 4] z = 0 def tests(): for z in len[x]: z = z + 1 if x: return y –  Jared Feb 11 '13 at 14:09

Your Answer



Browse other questions tagged or ask your own question.