Is the following code bad practice?
for i in some_values:
do_whatever(i)
do_more_things(i)
Somehow, it feels to me like the variable
Just like @petr said, it sound unnatural. Not because it's allowed that it's natural or you have to use it.
I rather have something like this, although it may not apply to the logic with a break use-case:
for i in some_values:
do_whatever(i)
else:
do_more_things(i)
But this still raise NameError if some_values evaluate to empty, but sounds clearer. It does not give the clear readability of an inner scope but the indentation may suggests it.
But as other said, to answer to the specific OP's question, yes, it's legal.