15 October 2015
*Selection Definition
Syntax :
-If
-If-else
-Switch-case
*If,syntax : -> Kondisi Kompleks
if(boolean expression) statements
Nested-If
syntax :
if(boolean expression) statements 1;
if(boolean expression) statements 2;
if(boolean expression) statements 3;
or
if(boolean expression) statement 1
else
if(boolean expression) statement 2
else
if(boolean expression) statement 3
*Switch-case
-tidak sekompleks if
-contohnya menghitung huruf konsonan
-Syntax:
switch(expression){
case constant:statement 1;break;
case constant:statement 2;break;
default:statements;
}
*?:Operator
syntax :
condition?then-expression
:else-expression
if(a>b)
max_value=a;
else
max_value=b;
as
max_value=(a>b)
?a:b;
*Jenis error:
+Compile-time error
caused by syntax error
+Link-time error
Success full compiled,but cause link error
Caused by no object code at link time
+Run time error
Successfully cimpiled,but error at runtime
+Logical error
Program jalan tapi output salah
*In an algorithm implementation,an instruction or block of instructions may be executed (or not) with certain pre determinated condition, that’s why we use selection.