SlideShare a Scribd company logo
1 of 23
6. Struktur Kontrol
Secara mendasar, struktur program
dapat dibagi menjadi 3 :
 Pemilihan

(Selection)
 Pengulangan (Iteration)
 Urutan (Sequence)
6.2. Perulangan (Iteration)
Digunakan untuk memeriksa jika suatu syarat
terpenuhi maka akan dikerjakan perintah
berulang.
Struktur kontrol perulangan terdiri atas 4
bentuk :
 FOR
 WHILE
 DO……WHILE
 FOREACH
STRUKTUR PERULANGAN
6.2.1 FOR
Sintaks :

FOR(inisialisasi; kondisi; counter) {
perintah_yang_diulang ;
}

Contoh (6.2.1.php):
<?
FOR ($a = 1; $a <= 10; $a++) {
Echo “$a”;
}
?>
LATIHAN 1, STRUKTUR FOR
Buatlah script untuk menampilkan tahun antara tahun
2012 – 2020, dan ditampilkan secara menurun sbb :
2012
2013
2014
2015
2016
2017
2018
2019
2020
LATIHAN 2, STRUKTUR FOR
Buatlah script untuk menampilkan angka ganjil antara 1
– 99, dan ditampilkan secara mendatar sbb :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45
47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83
85 87 89 91 93 95 97 99
LATIHAN 3, STRUKTUR FOR
Buatlah script untuk menampilkan angka genap antara
20 – 80, dan ditampilkan secara mendatar sbb :
20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56
58 60 62 64 66 68 70 72 74 76 78 80
LATIHAN 4, STRUKTUR FOR
Buatlah script untuk menampilkan tahun kabisat antara
tahun 2001 – 2025, dan ditampilkan secara menurun
sbb :
2004
2008
2012
2016
2020
2024
STRUKTUR PERULANGAN
6.2.2 WHILE
Sintaks :

Inisialisasi;
WHILE(kondisi) {
perintah_yang_diulang ;
counter;
}

Contoh (6.2.2.php):
<?
$a = 1;
WHILE ($a <= 10) {
Echo “$a”;
$a++;
}
?>
LATIHAN 1, STRUKTUR WHILE
Buatlah script untuk menampilkan tahun antara tahun
2012 – 2020, dan ditampilkan secara menurun sbb :
2012
2013
2014
2015
2016
2017
2018
2019
2020
LATIHAN 2, STRUKTUR WHILE
Buatlah script untuk menampilkan angka ganjil antara 1
– 99, dan ditampilkan secara mendatar sbb :
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45
47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83
85 87 89 91 93 95 97 99
LATIHAN 3, STRUKTUR WHILE
Buatlah script untuk menampilkan angka genap antara
20 – 80, dan ditampilkan secara mendatar sbb :
20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56
58 60 62 64 66 68 70 72 74 76 78 80
LATIHAN 4, STRUKTUR WHILE
Buatlah script untuk menampilkan tahun kabisat antara
tahun 2001 – 2025, dan ditampilkan secara menurun
sbb :
2004
2008
2012
2016
2020
2024
STRUKTUR PERULANGAN
6.2.3 DO….WHILE
Sintaks :

Inisialisasi;
DO{
perintah_yang_diulang ;
counter;
} WHILE (Kondisi);

Contoh (6.2.3.php):
<?
$a = 1;
DO{
Echo “$a”;
$a++;
} WHILE ($a <= 10);
?>
LATIHAN 1, STRUKTUR DO…WHILE
Buatlah script untuk menampilkan space Memory
(Flasdisk) dari 1GB – 100GB:
1 GB
2 GB
4 GB
8 GB
16 GB
32 GB
64 GB
128 GB
256 GB
512 GB
STRUKTUR PERULANGAN
6.2.4 FOREACH
Struktur perulangan FOREACH biasanya digunakan untuk membaca nilai suatu
array, jika nilai semuanya telah terbaca, maka perulangan akan dihentikan

Sintaks :

FOREACH(nama_array as nilai)

Contoh (6.2.4.php):
<?
$a = array("Ida","Ana","Edi","Eko","Edo","Adi");
FOREACH($a as $nama)
echo "$nama<br>";
?>
So’al
 Gunakan struktur pengulangan untuk
menampilkan angka seperti dibawah ini

1
22
333
4444
55555
66666
777777
SELESAI
TERIMA KASIH

More Related Content

Viewers also liked

Sbottonare la creatività stefano pollini 28 ottobre 2015
Sbottonare la creatività stefano pollini 28 ottobre  2015Sbottonare la creatività stefano pollini 28 ottobre  2015
Sbottonare la creatività stefano pollini 28 ottobre 2015stefano pollini
 
Final project museum tepotzotlán
Final project museum tepotzotlánFinal project museum tepotzotlán
Final project museum tepotzotlánPacman Toxicore
 
Do not let them die mastitis en bovino- 201339027
Do not let them die mastitis en bovino- 201339027Do not let them die mastitis en bovino- 201339027
Do not let them die mastitis en bovino- 201339027Dorelly Lunytha
 
Clases de modelos pedagógicos
Clases de modelos pedagógicosClases de modelos pedagógicos
Clases de modelos pedagógicoscolsemsur2014
 
BKK, Cycling developments in Budapest, 2013 February
BKK, Cycling developments in Budapest, 2013 FebruaryBKK, Cycling developments in Budapest, 2013 February
BKK, Cycling developments in Budapest, 2013 FebruaryKovács Virág
 
Psicologia tema 1 de 2013
Psicologia tema 1 de 2013Psicologia tema 1 de 2013
Psicologia tema 1 de 2013oscarmedina61
 
B1 book 01 - glauberto o liveira
B1   book 01 - glauberto o liveiraB1   book 01 - glauberto o liveira
B1 book 01 - glauberto o liveiraGerson Moura
 

Viewers also liked (11)

Sbottonare la creatività stefano pollini 28 ottobre 2015
Sbottonare la creatività stefano pollini 28 ottobre  2015Sbottonare la creatività stefano pollini 28 ottobre  2015
Sbottonare la creatività stefano pollini 28 ottobre 2015
 
Final project museum tepotzotlán
Final project museum tepotzotlánFinal project museum tepotzotlán
Final project museum tepotzotlán
 
Do not let them die mastitis en bovino- 201339027
Do not let them die mastitis en bovino- 201339027Do not let them die mastitis en bovino- 201339027
Do not let them die mastitis en bovino- 201339027
 
Мне нечем гордиться, но есть за что благодарить
Мне нечем гордиться, но есть за что благодаритьМне нечем гордиться, но есть за что благодарить
Мне нечем гордиться, но есть за что благодарить
 
Chromosomes
Chromosomes Chromosomes
Chromosomes
 
Clases de modelos pedagógicos
Clases de modelos pedagógicosClases de modelos pedagógicos
Clases de modelos pedagógicos
 
BKK, Cycling developments in Budapest, 2013 February
BKK, Cycling developments in Budapest, 2013 FebruaryBKK, Cycling developments in Budapest, 2013 February
BKK, Cycling developments in Budapest, 2013 February
 
Simon Mainwaring_We First
Simon Mainwaring_We FirstSimon Mainwaring_We First
Simon Mainwaring_We First
 
Key wot
Key wotKey wot
Key wot
 
Psicologia tema 1 de 2013
Psicologia tema 1 de 2013Psicologia tema 1 de 2013
Psicologia tema 1 de 2013
 
B1 book 01 - glauberto o liveira
B1   book 01 - glauberto o liveiraB1   book 01 - glauberto o liveira
B1 book 01 - glauberto o liveira
 

More from Ariezsam

More from Ariezsam (7)

Install win7.ppt
Install win7.pptInstall win7.ppt
Install win7.ppt
 
Bab 5
Bab 5Bab 5
Bab 5
 
Bab 3
Bab 3Bab 3
Bab 3
 
Bab 2
Bab 2Bab 2
Bab 2
 
Php 1
Php 1Php 1
Php 1
 
Php 0
Php 0Php 0
Php 0
 
Flowchat
FlowchatFlowchat
Flowchat
 

Bab 4

  • 1.
  • 2. 6. Struktur Kontrol Secara mendasar, struktur program dapat dibagi menjadi 3 :  Pemilihan (Selection)  Pengulangan (Iteration)  Urutan (Sequence)
  • 3. 6.2. Perulangan (Iteration) Digunakan untuk memeriksa jika suatu syarat terpenuhi maka akan dikerjakan perintah berulang. Struktur kontrol perulangan terdiri atas 4 bentuk :  FOR  WHILE  DO……WHILE  FOREACH
  • 5. 6.2.1 FOR Sintaks : FOR(inisialisasi; kondisi; counter) { perintah_yang_diulang ; } Contoh (6.2.1.php): <? FOR ($a = 1; $a <= 10; $a++) { Echo “$a”; } ?>
  • 6. LATIHAN 1, STRUKTUR FOR Buatlah script untuk menampilkan tahun antara tahun 2012 – 2020, dan ditampilkan secara menurun sbb : 2012 2013 2014 2015 2016 2017 2018 2019 2020
  • 7. LATIHAN 2, STRUKTUR FOR Buatlah script untuk menampilkan angka ganjil antara 1 – 99, dan ditampilkan secara mendatar sbb : 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
  • 8. LATIHAN 3, STRUKTUR FOR Buatlah script untuk menampilkan angka genap antara 20 – 80, dan ditampilkan secara mendatar sbb : 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80
  • 9. LATIHAN 4, STRUKTUR FOR Buatlah script untuk menampilkan tahun kabisat antara tahun 2001 – 2025, dan ditampilkan secara menurun sbb : 2004 2008 2012 2016 2020 2024
  • 11. 6.2.2 WHILE Sintaks : Inisialisasi; WHILE(kondisi) { perintah_yang_diulang ; counter; } Contoh (6.2.2.php): <? $a = 1; WHILE ($a <= 10) { Echo “$a”; $a++; } ?>
  • 12. LATIHAN 1, STRUKTUR WHILE Buatlah script untuk menampilkan tahun antara tahun 2012 – 2020, dan ditampilkan secara menurun sbb : 2012 2013 2014 2015 2016 2017 2018 2019 2020
  • 13. LATIHAN 2, STRUKTUR WHILE Buatlah script untuk menampilkan angka ganjil antara 1 – 99, dan ditampilkan secara mendatar sbb : 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99
  • 14. LATIHAN 3, STRUKTUR WHILE Buatlah script untuk menampilkan angka genap antara 20 – 80, dan ditampilkan secara mendatar sbb : 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80
  • 15. LATIHAN 4, STRUKTUR WHILE Buatlah script untuk menampilkan tahun kabisat antara tahun 2001 – 2025, dan ditampilkan secara menurun sbb : 2004 2008 2012 2016 2020 2024
  • 17. 6.2.3 DO….WHILE Sintaks : Inisialisasi; DO{ perintah_yang_diulang ; counter; } WHILE (Kondisi); Contoh (6.2.3.php): <? $a = 1; DO{ Echo “$a”; $a++; } WHILE ($a <= 10); ?>
  • 18. LATIHAN 1, STRUKTUR DO…WHILE Buatlah script untuk menampilkan space Memory (Flasdisk) dari 1GB – 100GB: 1 GB 2 GB 4 GB 8 GB 16 GB 32 GB 64 GB 128 GB 256 GB 512 GB
  • 20. 6.2.4 FOREACH Struktur perulangan FOREACH biasanya digunakan untuk membaca nilai suatu array, jika nilai semuanya telah terbaca, maka perulangan akan dihentikan Sintaks : FOREACH(nama_array as nilai) Contoh (6.2.4.php): <? $a = array("Ida","Ana","Edi","Eko","Edo","Adi"); FOREACH($a as $nama) echo "$nama<br>"; ?>
  • 21.
  • 22. So’al  Gunakan struktur pengulangan untuk menampilkan angka seperti dibawah ini 1 22 333 4444 55555 66666 777777