Page 11 - control flow
P. 11

 Translasi Umum - While                                                Contoh Loop - For


         Kode C

                                                                             int result;
                                                                             for (result = 1;

                                                                                       p != 0;
                                                                                       p = p>>1) {

     Versi Do-While                                                              if (p & 0x1)
                                         Versi Goto                                  result *= x;

                                                                                 x = x*x;
                                                                             }


                                                                             Bentuk Umum



                                                                               for (Init; Test; Update )

                                                                                       Body


                                       Inisialisasi                      Tes                        Update

     Translasi                        result = 1                   p != 0                       p = p >> 1

      Umum -                                                      {

                                                                      if (p & 0x1)
      For                                                                 result *= x;
                                                Body
                                                                      x = x*x;
                                                                  }
     Versi For
                                                            Versi Do-While                       Versi Goto


    for (Init; Test; Update )
                                                                Init;                               Init;

            Body                                                if (!Test)                          if (!Test)

                                                                     goto done;                         goto done;
 V   Versi While
                                                                do {                           loop:
                                                                     Body                           Body
  Init;
                                                                     Update ;                       Update ;
  while (Test ) {
          Body                                                  } while (Test)                      if (Test)
                                                            done:                                       Gotoloop;
          Update ;
                                                                                               done:
  }
   6   7   8   9   10   11   12   13   14