how do i generate inner loops in java?

You can use Recursion (see wiki https://en.wikipedia.org/wiki/Recursion_(computer_science))

for example (draft, not checking)

@Test
public void buildTaskList1() {
    String jobName ="job";
    int depth=5;
    int max=3;
    List<String> tasks = new ArrayList<>();
    for (long i = 1; i <= max; i++) {
        buildTaskListRecursion(max, depth, tasks, jobName + "."+i);
    }
    tasks.add(jobName+"."+(max+1)+"*");
}


public void buildTaskListRecursion(int max,int depth, List<String> tasks, String jobName){
    String last="";
    for (long j = 1; j <= max; j++) {
        if (j==max){
            last="*";
            tasks.add(jobName+"."+j+last);
        }else {
            depth--;
            if(depth > 0) {
                buildTaskListRecursion(max, depth, tasks, jobName+"."+j);
            } else {
                tasks.add(jobName+"."+j);
            }
        }
    }
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top