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