คำสั่งควบคุมลำดับการทำงาน switch/case
รูปแบบ
switch  (ตัวแปร)
{
    case (ค่าที่ 1):
      คำสั่ง 1;
      คำสั่ง 2;
      ..........;
      break;
    case (ค่าที่ 2):
      คำสั่ง 1;
      คำสั่ง 2;
      ..........;
      break;
    .
    .
    .
    default :
      คำสั่ง ..;
}
ตัวอย่าง Flowchart การทำงาน
ตัวอย่าง source code จาก flowchart
#include  <stdio.h>
#include  <conio.h>
#include  <graphics.h>
void main()
{
     clrscr();
     char ch;
     printf("Press select to draw\n");
     printf("1. draw circle\n");
     printf("2. draw triangle\n");
     printf("3. draw regtangle\n");
     printf(" select : ");
     ch=getch();
     int gdriver = DETECT, gmode, errorcode;
     initgraph(&gdriver, &gmode, "c:/tc/bgi/");
     switch (ch)
     {
         case ('1') :
           circle(100,200,50);
           break;
         case('2') :
           line(50,50,200,50);
           line(200,50,50,200);
           line(50,200,50,50);
           break;
         case('3') :
           rectangle(100,100,300,300);
           break;
         default :
           circle(100,200,50);
           line(50,50,200,50);
           line(200,50,50,200);
           line(50,200,50,50);
           rectangle(100,100,300,300);
     }
     getch();
     closegraph();
}
กลับหน้าหลัก |