90 likes | 263 Views
STRU CTURAL C ONTROL STATEMENT If If…..else…. If …. elseif …else. A PHP script is a set of statements Statements can be assignments / assignment, function calls, loops, conditions even an empty statement. In general, statements end with a semicolon (;). Statement IF.
E N D
STRUCTURALCONTROL STATEMENT • If • If…..else…. • If ….elseif…else
A PHP script is a set of statements • Statements can be assignments / assignment, function calls, loops, conditions even an empty statement. • In general, statements end with a semicolon (;)
Statement IF • Used to execute a block of statements if it meets certain conditions • The syntax is: • If the condition is true (true), the statement block will be done. if (condition) statement block
Example If <html> <head> <title> statement if </title> </head> <body> <?php $Nilai = 95; $Keterangan = "Tidak Lulus"; if ($Nilai >=60) { $Keterangan = "Lulus";} printf("Nilai = %d <br>", $Nilai); printf("Keterangan = %s<br>",$Keterangan); ?> </body> </html>
If more than one statement if($Tipe=2){ $Tabungan = "Perusahaan Kecil"; $Sukubunga=3.3; } if($Tipe=3){ $Tabungan = "Perusahaan Besar"; $Sukubunga=3.6; } print ("Tipe Tabungan = $Tipe <br>"); print ("Jenis Tabungan= $Tabungan<br>"); print ("SukuBunga = $Sukubunga <br>"); ?> </body> </html> <html> <head> <title>Statement if </title> </head> <body> <?php $Tabungan = ""; $Sukubunga = 0; $Tipe=1; if($Tipe=1){ $Tabungan = "Pribadi"; $Sukubunga=2.6; }
<html> <head> <title>statement IF</title> </head> <body> <form> NilaiSiswa : <Input Type="text" name="Nilai" <br><br> <input type="submit" value="Kelulusan"> </form> <?php if (isset ($Nilai)) { //Mengambilnilai integer $Nilai = intval ($Nilai); if ($Nilai >= 60) { $Keterangan = "Lulus"; } else { $Keterangan = "Tidak Lulus"; } print ("NilaiUjian = $Nilai <br>"); print ("Keterangan = $Keterangan"); } ?> </body> </html>
Statement If…Else… • Principally similar to the statement of if • If ... else ... used for two branching. • If a condition is met, then do a block ofstatement 1, if not met, do block of statements 2. • syntax if (kondisi) { blokpernyataan 1; } Else { blokpernyataan 2; } if (kondisi): blok pernyataan1; Else: blok pernyataan2; Endif; atau
Example, if..elseif..else elseif ($Nilai >=60) $Indeks = "D"; else $Indeks = "E"; if ($Nilai >=60) $Keterangan = "Lulus"; else $Keterangan = "Tidak Lulus"; print ("Nilai Ujian = $Nilai <br>"); print ("Keterangan = $Keterangan<br>"); print ("Indeks =$Indeks"); } ?> </body> </html> <html> <head> <title>Statement IF</title> </head> <body> <form> Nilai Siswa: <input type="text" name="Nilai" <br><br> <input type="submit" value ="kelulusan"> </form> <?php if (isset($Nilai)) { if ($Nilai >=90) $Indeks = "A"; elseif ($Nilai >=80) $Indeks = "B"; elseif ($Nilai >=70) $Indeks = "C";
The first meeting is finished, you can download these materials at www.stmik-tasikmalaya.ac.id, download the menu, the course material ( filename = PHPMySQL3,Kamboja.) thank you see you at the next meeting