Page 185 - การเขียนโปรแกรมบนมาตรฐานเปิด
P. 185

185


                       6.6 while Statements

                       while Statements ควรใช้รูปแบบดังนี้

               while (condition) {
                       statements;

               }

               และส าหรับ empty while statements  ควรใช้รูปแบบดังนี้

               (condition);
                       6.7 do-while Statements

                       do-while Statements ควรใช้รูปแบบดังนี้

               do {

                       statements;

               } while (condition);
                       6.8 switch Statements

               switch Statements ควรใช้รูปแบบดังนี้


               switch (condition) {


               case ABC:

                       statements;
                       /* falls through */

               Case DEF:

                       statements;

                       break:

               Case XYZ:
                       statements;

                       break;

               default:

               statements;

                       break;
               }

               ควรมี default ส าหรับทุก switch statements เพื่อป้องกันข้อผิดพลาดที่อาจเกิดขึ้นเมื่อมีการเพิ่ม case
   180   181   182   183   184   185   186   187   188   189   190