'how do I list everything that was eliminated by continue and put it in the output
I would like to print everything that was done by continue in the console output
public static void main(String[] args) {
String searchMe = "Look for a substring in me";
String substring = "sub";
boolean foundIt = false;
int max = searchMe.length() - substring.length();
test: for (int i = 0; i <= max; i++) {
int n = substring.length();
int j = i;
int k = 0;
while (n-- != 0) {
if (searchMe.charAt(j++) != substring.charAt(k++)) {
continue test;
}
}
foundIt = true;
break test;
}
System.out.println(foundIt ? "Found it" : "Didn't find it");
}
}
// font:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/branch.html
Solution 1:[1]
I don't know what you would like to print but continue here is basically skipping the rest of the code in the loop and going to the next iteration.
EXAMPLE
for (int i=1; i<=5;i++){ //loop through 1-5{
if (i==4){
continue;
}
System.out.println(i);
}
Will print 1 2 3 5.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Noah Wilhelm |
