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 9002599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:35:32+00:00 2026-06-16T00:35:32+00:00

Hello I’m new to programming and registered to this forum :) So I created

  • 0

Hello I’m new to programming and registered to this forum 🙂

So I created a little program with nested for loops that prints out all combinations of five numbers which can have a value from 0 to 5. With nested for-loops this works fine. But isn’t there a cleaner solution? I tried it with calling the for loop itself, but my brain doesn’t get the solution.. 🙁

//my ugly solution
int store1, store2, store3, store4, store5;
        for (int count = 0; count <= 5; count++) {
            store1 = count;
            for (int count2 = 0; count2 <= 5; count2++) {
                store2 = count2;
                for (int count3 = 0; count3 <= 5; count3++) {
                    store3 = count3;
                    for (int count4 = 0; count4 <= 5; count4++) {
                        store4 = count4;
                        System.out
                                .println(store1 + " " + store2 + " " + store4);
                }
 //I'm trying around with something like this 
    void method1() {
        for (int count = 0; count <= 5; count++) {
                    list.get(0).value = count;
            count++;
            method2();
        }
    }
    void method2() {
        for (int count = 0; count <= 5; count++) {
                    list.get(1).value = count;
            count++;
            method1();
        }
    }
  • 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-06-16T00:35:33+00:00Added an answer on June 16, 2026 at 12:35 am

    Usually when people try to use recursion or functional, using a loop is simpler or faster. However, in this case recursion is the simpler option in combination with a loop.

    public static void method(List<Integer> list, int n, int m) {
       if (n < 0) {
           process(list);
       } else {
          for(int i = 0; i < m; i++) {
             list.set(n, i);
             method(list, n-1, m);
          }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello the problem I'm having is this, I have a landing page (event.php) that
Hello! I've been programming for a long time but just started developing for android,
Hello I have like this 2 tables class User public int UserId{get;set;} { ....
Hello I've got this query to get users by email, which is an unique
hello for my app I need to save a record that the user type,
Hello I want to get Accurate location so that i have used following link
Hello guys i have been using JavaFx scene builder to build a gui that
Hello At my form I create TFrame at runtime. At this frame I create
Hello all and thanks for your time reading this. I need to verify certificates
hello all i am new to iphone development i am working on a application

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.