Triple nested loop python (While loop insde of for loop inside of while loop)

Isaac Won winefrog at gmail.com
Fri Mar 1 11:28:21 EST 2013


Thank you Ulich for reply,
What I really want to get from this code is m1 as I told. For this purpose, for instance, values of fpsd upto second loop and that from third loop should be same, but they are not. Actually it is my main question.
Thank you,
Isaac
On Friday, March 1, 2013 6:00:42 AM UTC-6, Ulrich Eckhardt wrote:
> Am 01.03.2013 09:59, schrieb Isaac Won:
> 
> > try to make my triple nested loop working. My code would be:
> 
> > c = 4
> 
> [...]
> 
> > while c <24:
> 
> >          c = c + 1
> 
> 
> 
> This is bad style and you shouldn't do that in python. The question that 
> 
> comes up for me is whether something else is modifying "c" in that loop, 
> 
> but I think the answer is "no". For that reason, use Python's way:
> 
> 
> 
>    for c in range(5, 25):
> 
>        ...
> 
> 
> 
> That way it is also clear that the first value in the loop is 5, while 
> 
> the initial "c = 4" seems to suggest something different. Also, the last 
> 
> value is 24, not 23.
> 
> 
> 
> 
> 
> 
> 
> >          while d <335:
> 
> >                  d = d + 1
> 
> >                  y = fpsd[d]
> 
> >                  y1 = y1 + [y]
> 
> >                 m = np.mean(y1)
> 
> >          m1 = m1 + [m]
> 
> 
> 
> Apart from the wrong indention (don't mix tabs and spaces, see PEP 8!) 
> 
> and the that "d in range(336)" is better style, you don't start with an 
> 
> empty "y1", except on the first iteration of the outer loop.
> 
> 
> 
> I'm not really sure if that answers your problem. In any case, please 
> 
> drop everything not necessary to demostrate the problem before posting. 
> 
> This makes it easier to see what is going wrong both for you and others. 
> 
> Also make sure that others can actually run the code.
> 
> 
> 
> 
> 
> Greetings from Hamburg!
> 
> 
> 
> Uli




More information about the Python-list mailing list