bramblephoenix
bramblephoenix

Reputation: 47

How does python treat a for loop within a range where upper bound and lower bound is the same?

So if i write the following code:

for i in range(1,1):
<whatever>

does the loop exit as the i value has already exceeded the upper bound or does something else occur within the loop?

Upvotes: 0

Views: 189

Answers (2)

Justin
Justin

Reputation: 299

It exists out of the loop without executing any loop statements.

Upvotes: 0

user9706
user9706

Reputation:

Why don't you just try it? The lower bound of a range is inclusive and the upper bound is exclusive (1, 1[ so the loop body doesn't get executed:

list(range(1,1))
[]

Upvotes: 1

Related Questions