pemrograman berorientasi objek
Download
Skip this Video
Download Presentation
PEMROGRAMAN BERORIENTASI OBJEK

Loading in 2 Seconds...

play fullscreen
1 / 31

PEMROGRAMAN BERORIENTASI OBJEK - PowerPoint PPT Presentation


  • 154 Views
  • Uploaded on

PEMROGRAMAN BERORIENTASI OBJEK. Kondisional Perulangan Percabangan. Struktur Kontrol. 1. Kondisional. Pernyataan if Pernyataan if – else Pernyataan if – else if Pernyataan switch. 2. Kondisional.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' PEMROGRAMAN BERORIENTASI OBJEK' - cate


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
pemrograman berorientasi objek

PEMROGRAMAN BERORIENTASI OBJEK

  • Kondisional
  • Perulangan
  • Percabangan

StrukturKontrol

1 kondisional
1. Kondisional
  • Pernyataan if
  • Pernyataan if – else
  • Pernyataan if – else if
  • Pernyataan switch
2 kondisional
2. Kondisional

Pernyataan kondisional memanfaatkan ekspresi boolean yang dapatberupa true atau false (sehinggadisebutbinary decision). Aksi yang dikerjakantergantungpadanilaihasildariekspresi:

pernyataan if
Pernyataan if
  • Pernyataan if menentukansebuah statement yang akandieksekusijikadanhanyajikapersyaratanboolean (boolean statement) bernilai true. Bentukumum :

if( boolean_expression )

statement;

Atau

if( boolean_expression ){

statement1;

statement2;

. . .

}

pernyataan if else
Pernyataan if - else

Pernyataan if-else digunakanapabilakitainginmengeksekusisebuah statement dengankondisitrue dan statement yang lain dengankondisi false.

Bentukumum :

if( boolean_expression ) atau if(boolean_expression)

statement; {

else statement1;

statement; statement2;

} else{

statement;

… ;

}

contoh
Contoh :

public class coba {

public static void main(String[]args)

{

int grade = 68;

if( grade > 60 ){

System.out.println(“selamat!");

System.out.println(“kamu lulus!");

}

else{

System.out.println(“maaf, kamutidak lulus");

}

}

}

pernyataan if else if
Pernyataan if-else if

Bentukumum :

if( boolean_expression1 )

statement1;

else if( boolean_expression2 )

statement2;

else

statement3;

pernyataan switch
Pernyataan switch

switch( switch_expression ){

case case_selector1:

statement1; //

statement2; //block 1

. . . //

break;

case case_selector2:

statement1; //

statement2; //block 2

. . . //

break;

. . .

default:

statement1; //

statement2; //block n

. . . //

break;

}

contoh1
Contoh :

public class coba {

public static void main(String[]args)

{

int grade = 80;

switch(grade){

case 100:

System.out.println( "Excellent!" );

break;

case 90:

System.out.println("Good job!" );

break;

case 80:

System.out.println("Study harder!" );

break;

default:

System.out.println("Sorry, you failed.");

}}}

2 perulangan
2. Perulangan
  • Pernyataan while
  • Pernyataan do..while
  • Pernyataan for
pernyataan while
Pernyataan while
  • Pernyataan while akandijalankansecaraterus-menerusselamakondisibernilaibenar(true).
  • Bentukumum :

while( boolean_expression )

{

statement1;

statement2;

. . .

}

contoh2
Contoh :

public class coba {

public static void main(String[]args)

{

inti = 4;

while ( i > 0 ){

System.out.print(i);

i--;

}

}

}

pernyataan do while
Pernyataan do..while
  • Pernyataan do..while, statement dieksekusisetidaknyasatu kali.
  • Bentukumum :

do{

statement1;

statement2;

. . .

}while( boolean_expression );

contoh3
Contoh :

public class coba {

public static void main(String[]args)

{

int x = 0;

do

{

System.out.print(x);

x++;

}while (x>10);

}

}

pernyataan for
Pernyataan for
  • Pernyataan for , melakukaneksekusipengulanganbeberapa kali.
  • Bentukumum :

for (Initialization; LoopCondition; StepExpression){

statement1;

statement2;

. . .

}

Initialization – inisialisasi dari variabel loop.

LoopCondition - membandingkanvariabel loop

padanilaibatas.

StepExpression - melakukan update pada

variabel loop.

contoh4
Contoh :

public class coba {

public static void main(String[]args)

{

inti;

for( i = 0; i < 10; i++ ){

System.out.print(i);

}

}

}

percabangan
Percabangan
  • Pernyataan break
  • Pernyataan continue
pernyataan break
Pernyataan break
  • Pernyataan break digunakan utk menghentikan jalannya statement.
  • Pernyataan break ada 2 :

- unlabeled break

- labeled break

unlabeled break
Unlabeled break

while(…){

while (…) {

if (…)

break;

} //akhir while terdalam

pernyataansesudah while

….

} //akhir while terluar

contoh5
Contoh :

public class cabang {

public static void main(String[]args)

{

int i=0, j=0;

while (i<3){

j=0;

while(j<5){

if (j==3)

break;

System.out.println("i = " + i +" j = "+ j);

j++;

}

i++;

}

}}

labeled break
Labeled break

selesai :

while(…){

while (…) {

if (…)

break selesai;

} //akhir while terdalam

pernyataansesudah while

….

} //akhir while terluar

Pernyataan_x;

Label

contoh6
Contoh

System.out.println("i = " + i +" j = "+ j);

j++;

}

i++;

}

System.out.println("Akhir program");

}

}

public class cabang {

public static void main(String[]args)

{

int i=0, j=0;

selesai:

while (i<3){

j=0;

while(j<5){

if (j==3)

break selesai;

pernyataan continue
Pernyataan continue
  • Pernyataancontunieberfungsiutkmengarahkaneksekusikekondisipernyataanperulanganshgkondisiakandievaluasilagi.
contoh8
Contoh :

public class cabang {

public static void main(String[]args)

{

inti=0;

while(i<5){

if (i==3){

i++;

continue;

}

System.out.println(i);

i++;

}

}

}

tugas
Tugas
  • Buat flowchart dan program utk- kondisional (if, if-else, switch)

- perulangan (while, do.. while, for)

- percabangan(break, continue)

ad