Java instance - continue Keyword Usage
Java continue with the statement to end the current cycle, and enter the next cycle, that is, only this time the end of a cycle, the cycle is not all over, behind the cycle continues to occur.
The following example uses the keyword continue to skip the current cycle and start the next cycle:
/* author by w3cschool.cc Main.java */ public class Main { public static void main(String[] args) { StringBuffer searchstr = new StringBuffer( "hello how are you. "); int length = searchstr.length(); int count = 0; for (int i = 0; i < length; i++) { if (searchstr.charAt(i) != 'h') continue; count++; searchstr.setCharAt(i, 'h'); } System.out.println("发现 " + count + " 个 h 字符"); System.out.println(searchstr); } }
The above code is run output is:
发现 2 个 h 字符 hello how are you.