Triple nested loop python (While loop insde of for loop inside of while loop)
Joel Goldstick
joel.goldstick at gmail.com
Fri Mar 1 08:00:01 EST 2013
On Fri, Mar 1, 2013 at 7:00 AM, Ulrich Eckhardt <
ulrich.eckhardt at dominolaser.com> 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.
>
>
>
> I concur with Uli, and add the following thoughts: What is going on with
[y]? Is this really a list? So what is y1 + y1 + [y] doing?
>
> while d <335:
>> d = d + 1
>> y = fpsd[d]
>> y1 = y1 + [y]
>> m = np.mean(y1)
>> m1 = m1 + [m]
>>
>
> In your outer loop you initialize these values each pass:
dt = 900.0 #Time step (seconds)
fs = 1./dt #Sampling frequency
This should me moved out of the loop since nothing changes with dt or fs
> 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
>
>
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
--
Joel Goldstick
http://joelgoldstick.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130301/c8fb7bd6/attachment.html>
More information about the Python-list
mailing list