Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
variable loop depth
#5
it still looks bigger and more complex than doing recursion. what i am worried about next is whether or not i can do a yield in the recursive function. during the many loops in the recursion there is a point where the total equals or exceeds a limit. if it exceeds the limit, that last loop is broken out of and the recursion returns to the previous loop for it next try. but if it equals the limit, i want to yield the list of all the iterated values before doing that recursion descent. i just want to be sure that yield mechanism can resume the recursive stack. i supposed i can just try it and see. the alternative would be to print the list and have the code that needs to process these values just read them from a pipe. each loop in one recursion has the same range. there will be many such recursions being run to look for specific results each with different ranges. this may involve a lot of CPU time. hopefully, your code ideas overcome that extra code by avoiding the extra overhead. but i may have to still go back and redo this in C. but there are somE ideas i have for changes that could be hard to do in C.

here is code i am currently thinking around
def nestloop(xlist,abc,sum,limit):
    xlist.append(0)
    for num in range(*abc):
        xlist[-1] = num
        u = sum+num
        if u==limit:
            print(' '.join([repr(x) for x in xlist]))
            # or do a yield of xlist here
            break
        if u>limit:
            break
        nestloop(xlist,abc,u,limit)
    xlist.pop(-1)
    return
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
variable loop depth - by Skaperen - Jul-15-2018, 07:09 AM
RE: variable loop depth - by ichabod801 - Jul-15-2018, 12:18 PM
RE: variable loop depth - by Skaperen - Jul-17-2018, 01:25 AM
RE: variable loop depth - by ichabod801 - Jul-17-2018, 02:20 AM
RE: variable loop depth - by Skaperen - Jul-17-2018, 03:05 AM
RE: variable loop depth - by Skaperen - Jul-18-2018, 02:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Variable definitions inside loop / could be better? gugarciap 2 484 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 1,920 Nov-07-2023, 09:49 AM
Last Post: buran
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,668 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  loop (create variable where name is dependent on another variable) brianhclo 1 1,176 Aug-05-2022, 07:46 AM
Last Post: bowlofred
  Multiple Loop Statements in a Variable Dexty 1 1,231 May-23-2022, 08:53 AM
Last Post: bowlofred
Big Grin Variable flag vs code outside of for loop?(Disregard) cubangt 2 1,212 Mar-16-2022, 08:54 PM
Last Post: cubangt
  How to save specific variable in for loop in to the database? ilknurg 1 1,180 Mar-09-2022, 10:32 PM
Last Post: cubangt
  How to add for loop values in variable paulo79 1 1,485 Mar-09-2022, 07:20 PM
Last Post: deanhystad
  Max recursion depth.... Error MeloB 2 1,946 Feb-16-2022, 05:21 PM
Last Post: MeloB
  Using Excel Cell As A Variable In A Loop knight2000 7 4,218 Aug-25-2021, 12:43 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020