先查看代码:
public class ContinueTesting {
public static void main(String[] args) {
StringBuffer sb=new StringBuffer("peter piper picked a peck of pickled peppers");
int x=0;
System.out.println(sb.length());
for (int i=0;i<sb.length();i++){
if(sb.charAt(i)!='p')
continue;
x++;
sb.setCharAt(i, 'O');
}
System.out.println("found "+x+" p's in the string");
System.out.println(sb);
}
}
输出结果:
44
found 9 p's in the string
Oeter OiOer Oicked a Oeck of Oickled OeOOers
含continue的代码块:
for (int i=0;i<sb.length();i++){
if(sb.charAt(i)!='p')
continue;
x++;
sb.setCharAt(i, 'O');
}
continue的功能:
终止当前的这轮循环,即跳过continue语句后面的剩余的语句,并计算和判断循环条件,决定是否进入下一轮循环。
注意:
if(sb.charAt(i)!='p') 后面不接{}也是可以通过编译的,默认if后面的statement为{}内容.. 此处程序相当于
if(sb.charAt(i)!='p') {continue;}
分享到:
相关推荐
Idiot‘s_Guides_to_Beginning_Programming.pdf
An Idiot's Guide to C++ Templates
Idiot
The Complete Idiot’s Guide to iPad and iPhone App Development .pdf
The Complete Idiot's Guide to Improving Your IQ.pdf
傻瓜指南系列-如何作小生意]The.Complete.Idiot's.Guide.-.Small.Business.pdf
Explorer扩展编程的指导资料,包括一个chm教程以及其对应的源代码。 Part I - A step-by-step tutorial on writing shell extensions Part II - A tutorial on writing a shell extension that operates on ...
idiot
详细说明Windows Shell的编程指南,可以处理Windows Explorer资源管理器很多的交互,比如文件复制和剪切,鼠标右键菜单的添加,任意文件的图标的修改和叠加,系统文件拷贝进度条的控制等等,文件属性自定义扩展页和...
An Idiot’s guide to Support vector machines (SVMs)
加密已有文件,可以临时加密和永久解密;加密特定文件夹
This guide helps environmentally conscious people make real-world ...·More than 80 regional and local green building programs are in place in the U.S. and more are being promoted in the private sector
HTML Reference for dummies, idiot, beginner
most simple adding for those idiot
CSS 2 Reference for begginer, idiot, dummies
American Idiot is the seventh studio album by American rock band Green Day
笨蛋 物联网ID
crap idiots dumb admin - asshole