Apr-14-2018, 02:03 AM
Hello,
I'm testing to use a for loop that stops by 2 conditions. For example:
Is it possible?
Thanks
I'm testing to use a for loop that stops by 2 conditions. For example:
l1 = ['hello', 'bye', 'now', 'before', 'after'] count = 3 for word in l1: print(word)But I want to stop not only when l1 is finished, also when count is 0, and I do it:
l1 = ['hello', 'bye', 'now', 'before', 'after'] count = 3 for word in l1: count -=1 print(word) if count == 0: breakI don't like... I think that Python should provide me with a more elegant way to do it.
Is it possible?
Thanks