1. Java
  • Statement = perintah
  • Looping = perintah berulang berurutan
  • For

For (expression1; condition; expression2)

{statements}

  1. While

While (condition)

{statements}

  1. Do-While

Do {statements}

While (condition )

  1. Selection = menyeleksi perintah sesuai kondisi
  2. Switch case

Switch (variable){

Case a:

Statements;

Break;

Default:

Statements;

Break;

}

 

  1. If-else

If (condition)

{statement;}

Else if (condition)

{statement;}

Else (condition)

{statement;}

 

  1. Boolean

==              equal

!=              not equal

<                less than

<=              less than or equal with

>                greater than

>=              greater than or equal with

  1. C++
  2. Iterative
  3. Counter-control loop

For (expression1; condition; expression2)

{statements;}

  1. Pretest logically control loop

While (condition)

{statements;}

  1. Post test logically control loop

Do {statements;}

While (condition)

  1. Selection
  2. Multiple Ways

Switch (variable){

Case a:

Statements;

Break;

Default:

Statements;

Break;

}

 

  1. Two Ways

If (Boolean expression)

{statement;}

Else if (Boolean expression)

{statement;}

Else (Boolean expression)

{statement;}

 

  1. HTML (Javascript)
  2. Selection
  3. If-else

Example :

<html>

<body>

<script type=“text/javascript”>

var book=“maths”;

if(book==“history”){

document.write(“History book”);

}

else if (book==“maths”){

document.write(“Maths Book”);

}

else { document.write(“unknown book”);}

</script>

</body>

</html>

 

  1. Switch

Example :

<html>

<body>

<script type=”text/javascript”>

var grade=’A’;

document.write(“Entering switch block<br />”);

switch (grade)

{

case ‘A’: document.write(“Good job<br />”);

break;

case ‘B’: document.write(“Pretty good<br />”);

break;

case ‘C’: document.write(“Passed<br />”);

break;

case ‘D’: document.write(“Not so good<br />”);

break;

case ‘F’: document.write(“Failed<br />”);

break;

default:  document.write(“Unknown grade<br />”)

}

document.write(“Exiting switch block”);

</script>

<p>Set the variable to different value and then try…</p>

</body>

</html>

 

  1. Iterative
  2. While

Example :

<html>

<body>

<script type=”text/javascript”>

var count = 0;

document.write(“Starting Loop “);

while (count < 10){

document.write(“Current Count : ” + count + “<br />”);

count++;

}

document.write(“Loop stopped!”);

</script>

<p>Set the variable to different value and then try…</p>

</body>

</html>

 

  1. Do – While

Example :

<html>

<body>

<script type=”text/javascript”>

var count = 0;

document.write(“Starting Loop” + “<br />”);

do{

document.write(“Current Count : ” + count + “<br />”);

count++;

}

while (count < 5);

document.write (“Loop stopped!”);

</script>

<p>Set the variable to different value and then try…</p>

</body>

</html>

 

  1. For

Example :

<html>

<body>

<script type=”text/javascript”>

var count;

document.write(“Starting Loop” + “<br />”);

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

document.write(“Current Count : ” + count );

document.write(“<br />”);

}

document.write(“Loop stopped!”);

</script>

<p>Set the variable to different value and then try…</p>

</body>

</html>

Leave a Reply