Path: csiph.com!goblin1!goblin3!goblin.stu.neva.ru!panix!gordon From: John Gordon Newsgroups: comp.lang.python Subject: Re: Resetting the Range start in the middle of a loop Date: Fri, 23 Oct 2015 17:15:51 +0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Lines: 39 Message-ID: References: NNTP-Posting-Host: panix1.panix.com X-Trace: reader1.panix.com 1445620551 2998 166.84.1.1 (23 Oct 2015 17:15:51 GMT) X-Complaints-To: abuse@panix.com NNTP-Posting-Date: Fri, 23 Oct 2015 17:15:51 +0000 (UTC) User-Agent: nn/6.7.3 Xref: csiph.com comp.lang.python:97922 In bigred04bd3@gmail.com writes: > 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. You can't do this. The range is only calculated once, and changing s or i afterwards is too late to have any effect. You could use a while loop instead, like this: i = 1 while i <= 1000: # do stuff... if some_condition: # skip ahead in the loop i = i + 100 else: # move i ahead normally i = i + 1 -- John Gordon A is for Amy, who fell down the stairs gordon@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies"