D?ng 1: while(
)
while(?i?u_ki?n_l?p){
kh?i_l?nh;
}
Xét ?i?u ki?n tr??c, ?úng r?i m?i th?c hi?n kh?i l?nh. Vd:?
while(?i?u_ki?n_l?p){
kh?i_l?nh;
}
Xét ?i?u ki?n tr??c, ?úng r?i m?i th?c hi?n kh?i l?nh. Vd:?
PHP:
public class AndroidVn {
public static void main(String[] args) {
int i;
i = 0;
while (i < 10) {
System.out.print(" "+i++);
}
System.out.println("...i = "+i);
i = 15;
while (i < 10) {
System.out.print(" "+i++);
}
System.out.println("...i = "+i);
}
}
D?ng 2: do{ }while;
do{
kh?i_l?nh;
}while(?i?u_ki?n);
Th?c hi?n kh?i l?nh tr??c, r?i xét ?i?u ki?n, n?u sai thì không th?c hi?n n?a. Nh? v?y, ngay c? ?i?u ki?n sai t? l?n ??u, t? kh?i l?nh luôn ???c th?c hi?n ít nh?t 1 l?n. Vd:?
PHP:
public class AndroidVn {
public static void main(String[] args) {
int i = 0;
do {
System.out.print(" " + i++);
} while (i < 10);
System.out.println("...i = " + i);
i = 15;
do {
System.out.print(" " + i++);
} while (i < 10);
System.out.println("...i = " + i);
}
}
D?ng 3: for( )
for(kh?i_t?o_bi?n_??m;?k_l?p;t?ng_bi?n){
<kh?i_l?nh>;
}
Vd:?
PHP:
public class AndroidVn {
public static void main(String[] args) {
int i;
for (i = 0; i < 10; i++) {
System.out.print(" " + i);
}
System.out.println(" ..i = " + i);
}
}
?? hi?u h?n các c?u trúc, các b?n tham kh?o thêm
Video c?a Blog StudyAndShare
?
Video c?a Blog StudyAndShare
?
Ngu?n : Android.vn