Java interesting syntax

时间:2018-02-03 11:11:07

标签: java

I was looking at the source code for String.toUpperCase() and I came across this syntax which is quite unfamiliar to me. What does it mean?

scan: {
        for (firstLower = 0 ; firstLower < len; ) {
            int c = (int)value[firstLower];
            int srcCount;
            if ((c >= Character.MIN_HIGH_SURROGATE)
                    && (c <= Character.MAX_HIGH_SURROGATE)) {
                c = codePointAt(firstLower);
                srcCount = Character.charCount(c);
            } else {
                srcCount = 1;
            }
            int upperCaseChar = Character.toUpperCaseEx(c);
            if ((upperCaseChar == Character.ERROR)
                    || (c != upperCaseChar)) {
                break scan;
            }
            firstLower += srcCount;
        }
        return this;
    }

I couldn't quite understand what scan is for. Is it a keyword? I even tried this simple program and it ran.

public static void main(String[] args) {
    scan:
    {
        System.out.println("Hello");
    }
}

1 个答案:

答案 0 :(得分:2)

That's a Jump-out label.

Some reference here. Very similar to Assembly language by the way, probably derived...