Nested For and While Statements
Paul McGuire
ptmcg at austin.rr.com
Mon Sep 24 16:01:52 EDT 2007
On Sep 24, 2:28 pm, kou... at hotmail.com wrote:
> I start my code with some constants then a while statement. But I
> have some For statements towards the end within the While statement
> where I start getting some errors. I'm hoping I won't have to post my
> code, but it looks something like this:
>
> Import os, string
>
> while this:
>
> All Code indented like it should
>
> Last line in While.
>
> For i in range(1)
> class = []
> class2 = []
> For i in range(2)
> Do this
> And this
> And that.
>
> Next Line hits snag here? Where should this line
> be?
Why are the for loops further indented than the body of the while? If
they are part of the while, "For i in range(1)" should line up with
"Last line in While." If they are not part of the while, but come
after, then "For i in range(1)" should line up with "while this:".
Also, as James Stroud said, your for loop indexes are the same
variable.
-- Paul
More information about the Python-list
mailing list