| คำสั่งควบคุมการทำงาน SWITCH CASE | คำสั่ง switch case คือ จะตรวจสอบค่าของตัวแปร ถ้าตรงตามเงื่อนไขใดก็จะทำตามคำสั่งนั้นๆ |
|---|
subject:คำสั่งควบคุมการทำงาน SWITCH CASE
syntax:switch ( variable ) { case value_1 : structure; break; case value_2 : structure; break; default : structure; break; }
content:คำสั่ง switch case คือ จะตรวจสอบค่าของตัวแปร ถ้าตรงตามเงื่อนไขใดก็จะทำตามคำสั่งนั้นๆ จนกว่าจะเจอ คำสั่ง break
example:int num = 100; switch ( num ) { case 100 : System.out.print ( "many" ); break; case 50 : System.out.print ( "middle" ); break; default : System.out.print ( "little" ); break; }