do-while声明时,至少一次会循环一次,。
它的语法如下:
do {undefined
statement (s)
} while (booleanexpression);
简单实例
public class mainclass {undefined
public static void main(string[] args) {undefined
int i = 0;
do {undefined
system.out.println(i);
i ;
} while (i < 3);
}
}
 以下do-while表明至少做块的代码会被执行,即使一次的初始值,用于测试的表达[j]. . < 3计算错误的。public class mainclass {undefined
public static void main(string[] args) {undefined
int j = 4;
do {undefined
system.out.println(j);
j ;
} while (j < 3);
}
}
 利用do while来求和public class mainclass {undefined
public static void main(string[] args) {undefined
int limit = 20;
int sum = 0;
int i = 1;
do {undefined
sum = i;
i ;
} while (i <= limit);
system.out.println("sum = " sum);
}
}