ตัวอย่างโค้ด
Code: Select all
class breakcon
{
public static void main(String[]args)
{
int x = 0;
while(x < 10)
{
++x;
if(x == 5) break; //ทำการเช็คค่า x เมื่อค่า x เพิ่มจนถึง 5 ให้ทำการหยุดลูป
System.out.print(" "+x);
}
}
}
Code: Select all
class breakcon
{
public static void main(String[]args)
{
int x = 0;
while(x < 10)
{
++x;
if(x == 5) continue; //เช็คค่า x เมื่อ x เท่ากับ 5 ให้ทำงานต่อ
System.out.print(" "+x);
}
}
}