1 / 9

STRU CTURAL C ONTROL STATEMENT If If…..else…. If …. elseif …else

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.

irina
Télécharger la présentation

STRU CTURAL C ONTROL STATEMENT If If…..else…. If …. elseif …else

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. STRUCTURALCONTROL STATEMENT • If • If…..else…. • If ….elseif…else

  2. 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 (;)

  3. 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

  4. 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>

  5. 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; }

  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>

  7. 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

  8. 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";

  9. 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

More Related