Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Peter Pearson Newsgroups: comp.lang.python Subject: Re: Resetting the Range start in the middle of a loop Date: 23 Oct 2015 17:23:51 GMT Lines: 30 Message-ID: References: X-Trace: individual.net HO7U4pCGQdB/hewKzFm6mAaaBQJqEZ3AGkHMB94BVj/c9bH7yT Cancel-Lock: sha1:vXTT2Y1AdneRWYrM4I73m1/JjZA= User-Agent: slrn/pre1.0.0-18 (Linux) Xref: csiph.com comp.lang.python:97923 On Fri, 23 Oct 2015 08:42:53 -0700 (PDT), bigred04bd3@gmail.com wrote: > I am wanting to reset a Range start while a loop is running. here is > what I have: > > s = 1 > for i in range(s, 1000): > # do stuff > for r in range(i, 1000): > # do stuff > s = s + 100 #example > break > > I've also tried to update the i as well, but it just continues on to > the next number as if it was never updated. > > any help would be great The "s = s + 100" cannot affect the outer for loop because by the time it is executed, the expression "range(s, 1000)" has already been evaluated (i.e., it has been turned into an object) and is in the grips of the outer "for" machinery. Beyond that, though, this is a peculiar thing to want to do. If you want to take such liberties with i, then a "for" probably isn't the clearest construction to use. If you share a *slightly* broader view of your goals, the unusually helpful experts in this group might treat us to an informative discussion of elegant ways to get there. -- To email me, substitute nowhere->runbox, invalid->com.