Existence of goto like statements in Java

Go to the middle stream and stop the flying boat 2022-01-26 20:10:05 阅读数:546

existence goto statements java

In my spare time , to glance at String Source code , Just to see Gets the index of the last occurrence of the substring Function of , One of the things that brightened my eyes was startSearchForLastChar: , be ashamed , I haven't seen this thing until now , Look like C++ Of goto sentence ,
however C++ Of goto Statement can be defined after the call , This can't be .
And the statement can only be with the loop .

static int lastIndexOf(char[] source, int sourceOffset, int sourceCount,
char[] target, int targetOffset, int targetCount,
int fromIndex) {
/*
* Check arguments; return immediately where possible. For
* consistency, don't check for null str.
*/
int rightIndex = sourceCount - targetCount;
if (fromIndex < 0) {
return -1;
}
if (fromIndex > rightIndex) {
fromIndex = rightIndex;
}
/* Empty string always matches. */
if (targetCount == 0) {
return fromIndex;
}
int strLastIndex = targetOffset + targetCount - 1;
char strLastChar = target[strLastIndex];
int min = sourceOffset + targetCount - 1;
int i = min + fromIndex;
startSearchForLastChar:
while (true) {
while (i >= min && source[i] != strLastChar) {
i--;
}
if (i < min) {
return -1;
}
int j = i - 1;
int start = j - (targetCount - 1);
int k = strLastIndex - 1;
while (j > start) {
if (source[j--] != target[k--]) {
i--;
continue startSearchForLastChar;
}
}
return start - sourceOffset + 1;
}
}
copyright:author[Go to the middle stream and stop the flying boat],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/01/202201262010031499.html