Question

I am trying to do conditional processing according to when we are at the last item in a range, for example:

for i in range(intNumberOfPlayers):            
        #If we are on the last item in the range, do this...
Was it helpful?

Solution

for i in range(intNumberOfPlayers):
    if i == intNumberOfPlayers - 1:
        print(i) #print last item

Ranges are not inclusive, so the last item is intNumberOfPlayers - 1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top