Recursion executing line after break statement

private String getPhrasedvalue(int current_value, int next_value, String str) throws SQLException {
String[] words = str.split(" “);
String current = words[current_value];
String next = words[next_value];
StringBuilder sb = new StringBuilder();
String lastToken = words[words.length-1];
StringBuilder finalstring = new StringBuilder();

    while (true) {
        boolean flag = FindDB(sb.toString());
            if (flag == true) {

            } else {

                int i = sb.toString().lastIndexOf("-");
                sb.replace(i, i + 1, " ");
                current_value = next_value;
                next_value = next_value + 1;
                    break Outer;
                getPhrasedvalue(current_value, next_value, str);


After going to if loop of break statement it will executing getPhrasedvalue(current_value, next_value, str); again .what is the problem? and how to get final appended value of sb?

I have several problems with your code

  • method returns String, but there is no return statement in method, is there something missing?
  • you are using break with label (Outer), why? there is no inner loop…

You didn’t even tried to describe what you are trying to do and what is in your DB.

For sure when break is reached it will end the while loop for sure, try replace your

if(next_value==words.length) break Outer;


if ( next_value >= words.length) break Outer;

that’s only tip I can provide now…

1 Like