Python: "breaking out" of if statement inside a for loop
if randomValue <= sum(i.freq for i in diceList[0:i+1]):
print 'O', i, 'randomValue', randomValue, 'prob container', sum(i.freq for i in diceList[0:i+1])
break
Break will terminate "the nearest enclosing loop, skipping the optional else clause if the loop has one." The outer loop will just continue with the next iteration. So you are not "breaking the if" but the loop the if is enclosed in. Before the break, you can just set all values from diceList[0:i+1]
to diceList[0:len(diceList)+1]
to true.
One method is to raise an exception in the inner code, and catch it inside the for loop and continue the loop.