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

  • Home
  • SEARCH
  • 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 7762637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:27:29+00:00 2026-06-01T14:27:29+00:00

I have an issue with a for loop in java. I’m trying to do

  • 0

I have an issue with a for loop in java. I’m trying to do an Iterative deeping search and the code for generating children at depth n looks like this:

for(Iterator<puzzleBoard> child = generateSuccessorsIDS(pb).iterator(); child.hasNext();){
    DLS(child.next(),(depth-1));
}

When not using the return statement the DLS does like it should do, but the value doesn’t reach the calling function because of the missing return statement. When using return DLS(…) it just returns the first value as the iterator generates. How to solve this? I paste the whole DLS and it’s caller function below.

private puzzleBoard IDS(String initial){
    puzzleBoard pb = new puzzleBoard(initial,0,new Vector<Integer>(),new Vector<puzzleBoard>(),new Vector<puzzleBoard>());

    puzzleBoard result=new puzzleBoard("999999999",0,new Vector<Integer>(),new Vector<puzzleBoard>(),new Vector<puzzleBoard>());
    for(int depth=0;depth<3;depth++){//Repeat
        System.out.println("DP "+depth);
        result = DLS(pb,depth);
        System.out.println("Here: "+result.toString());
        if(result.isGoalState())
            return result;
    }
    return new puzzleBoard("999999999",0,new Vector<Integer>());
}

private puzzleBoard DLS(puzzleBoard pb, int depth){

    pb.printPuzzle();
    if(depth==0 && pb.isGoalState()){
        System.out.println("!!!!!WOOOOOW!!!!!");
        return pb;
    }
    else if(depth>0){
        for(Iterator<puzzleBoard> child = generateSuccessorsIDS(pb).iterator(); child.hasNext();){
            DLS(child.next(),(depth-1));
        }
    }
    else
        return new puzzleBoard("999999999",0,new Vector<Integer>(),new Vector<puzzleBoard>(),new Vector<puzzleBoard>());
    return pb;
}
  • 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-01T14:27:30+00:00Added an answer on June 1, 2026 at 2:27 pm

    May be I am wrong, but I think you should place your for loop outside, where you are actually calling your function DLS(puzzleBoard pb, int depth) for the first time…..Inside your else if only call DLS(pb,depth);

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

Sidebar

Related Questions

I have the following issue with one of my Java programs. I'm trying to
I have an issue with php where code works on on computer but wont
Hey, so basically I have this issue, where I'm trying to put an equation
I'm trying to write Java code that executes some terminal commands. The code should
I currently have a small Java program which I would like to run both
I'm having an issue reading from a java input stream. I have a buffer
I have a program where I compile java code a user types into a
I have an issue with a function call in setTimeout in a loop. The
I have issue that is reproduced on g++. VC++ doesn't meet any problems. So
We are new to ROR, We have issue in creating Login/Logout process in ROR

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.