There is a task in which it is required to remove all substrings (remove) from a single string (base) without regard to case. The task was solved as follows:
public String withoutString(String base, String remove) { String result = ""; for (int i = 0; i < (base.length()-remove.length()+1); i++) if (!base.substring(i, i+remove.length()).toLowerCase().equals(remove.toLowerCase())) result += base.substring(i, i+1); else if (i+remove.length() < base.length()) i += remove.length()-1; else return result; for (int j = base.length()-remove.length()+1; j < base.length(); j++) result += base.substring(j, j+1); return result; } Without construction
else return result; the program passes all checks, except in the case of "Hi HoHo", "Ho" (output: "Hi o").
Question : why is the return needed here (the second one, in fact), and the same break statement will not work here?
Thank you.