1 / 31

# PEMROGRAMAN BERORIENTASI OBJEK - PowerPoint PPT Presentation

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

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

## PowerPoint Slideshow about ' PEMROGRAMAN BERORIENTASI OBJEK' - cate

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

• Kondisional

• Perulangan

• Percabangan

StrukturKontrol

1. Kondisional

• Pernyataan if

• Pernyataan if – else

• Pernyataan if – else if

• Pernyataan switch

2. Kondisional

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

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

if( boolean_expression )

statement;

Atau

if( boolean_expression ){

statement1;

statement2;

. . .

}

Flowchart Pernyataan if

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;

… ;

}

Flowchart Pernyataan if-else

public class coba {

public static void main(String[]args)

{

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

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

}

else{

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

}

}

}

Bentukumum :

if( boolean_expression1 )

statement1;

else if( boolean_expression2 )

statement2;

else

statement3;

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;

}

public class coba {

public static void main(String[]args)

{

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

• Pernyataan while

• Pernyataan do..while

• Pernyataan for

• Pernyataan while akandijalankansecaraterus-menerusselamakondisibernilaibenar(true).

• Bentukumum :

while( boolean_expression )

{

statement1;

statement2;

. . .

}

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, statement dieksekusisetidaknyasatu kali.

• Bentukumum :

do{

statement1;

statement2;

. . .

}while( boolean_expression );

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 , melakukaneksekusipengulanganbeberapa kali.

• Bentukumum :

for (Initialization; LoopCondition; StepExpression){

statement1;

statement2;

. . .

}

Initialization – inisialisasi dari variabel loop.

LoopCondition - membandingkanvariabel loop

variabel loop.

public class coba {

public static void main(String[]args)

{

inti;

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

System.out.print(i);

}

}

}

• Pernyataan break

• Pernyataan continue

• Pernyataan break digunakan utk menghentikan jalannya statement.

• Pernyataan break ada 2 :

- unlabeled break

- labeled break

while(…){

while (…) {

if (…)

break;

} //akhir while terdalam

pernyataansesudah while

….

} //akhir while terluar

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++;

}

}}

selesai :

while(…){

while (…) {

if (…)

break selesai;

} //akhir while terdalam

pernyataansesudah while

….

} //akhir while terluar

Pernyataan_x;

Label

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;

• Pernyataancontunieberfungsiutkmengarahkaneksekusikekondisipernyataanperulanganshgkondisiakandievaluasilagi.

public class cabang {

public static void main(String[]args)

{

inti=0;

while(i<5){

if (i==3){

i++;

continue;

}

System.out.println(i);

i++;

}

}

}

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

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

- percabangan(break, continue)