Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7533633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:46:53+00:00 2026-05-30T05:46:53+00:00

I am relatively new to programming. As the title suggests I require an algorithm

  • 0

I am relatively new to programming. As the title suggests I require an algorithm that lets me get the same function of a variable nested loop. i.e.

for(..)
{ for(..){
for(..){....}
.
.
}}

The Number of nested loop will vary depending upon user input. What I am trying to achieve is finding all combinations of the numbers (10,9,8,7,6,5,4) Now I have read many. Either I dont understand them fully (I am new to programming world) or It doesnt serve my purpose. I need these combinations later in certain calculations and not just print all the combinations. One way, as I have learnt is to use recursion. I dont understand it fully. I tried to make a recursive function but failed miserably. This is what I want

10 10 10 
10 10 9
10 10 8
.
.
.
4  4  4 

The number can change (like 10 10 10 10 , 10 10 10 9 .. ) These combinations are to be stored in an array as I need them to manipulate later. Please keep it simple and comment.

Preferred language will be java. Any Language will do. A general algorithm is highly recommended. P.S. This is not a homework.

Thanks to amit. Here is the working code

def findcombinations(array,n,sol,tt=[]):
    if (n== 0):
        tt.append(sol[:])
        return
    for x in array:
        sol.append(x)
        findcombinations(array,n-1,sol,tt)        
        del sol[-1]
    return tt      

To call the function use
print(findcombinations([1,2],3,[]))

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T05:46:55+00:00Added an answer on May 30, 2026 at 5:46 am

    Usually when you need “dynamic loops” – it is a strong indication you actually need recursion.

    For example, finding all possible combinations of size n of digits in array [pseudo code]:

    findCombinations(array,n,sol):
       if (sol.size == n): //stop condition for the recursion
          print sol
          return
       for each x in array:
          sol.append(x)
          findCombinations(array,n-1,sol) //recursive call
          sol.removeLast() //cleaning up environment
    

    The above pseudo-code will find and print all sequences of length n made from elements from array [each element can appear more then once]

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to programming so excuse me if I get some terms wrong
I'm relatively new to programming and trying get a (very) long list of information
We have a lot of staff that are relatively new to iOS programming and
Hii , I am relatively new to programming C++ . I do know that
I am relatively new to programming with Qt and had a question. Short version:
I am relatively new to programming. My work basically revolves around data and analysis.
I really need your help for this. I am relatively new to programming and
Being relatively new to functional programming, I expend lots of energy wondering is this
I'm relatively new to .NET programming (and OOP in general) and I want to
I'm relatively new to web application programming so I hope this question isn't too

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.