Wednesday, November 21, 2012

Module 5 Decision Making (Tep Senghak)



Nama: Tep Senghak
Nim: 49012084
Major: d4 TMD ITB Batch 6

Module 5

Decision Making

Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed if the condition is determined to be true, and optionally, other statements to be executed if the condition is determined to be false.

1. If statement

An if statement consists of a boolean expression followed by one or more statements.
Syntax:
if(boolean_expression)
{
/* statement(s) will execute if the boolean expression is true */
}

2. If else statement

An if statement can be followed by an optional else statement, which executes when the boolean expression is false.
Syntax:
if(boolean_expression)
{
    /* statement(s) will execute if the boolean expression is true */
}
else
{
    /* statement(s) will execute if the boolean expression is false */
}

3. If-else-else-if statement

An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement.

Syntax:
if(boolean_expression 1)
{
    /* Executes when the boolean expression 1 is true */
}
else if( boolean_expression 2)
{
    /* Executes when the boolean expression 2 is true */
}
else if( boolean_expression 3)
{
    /* Executes when the boolean expression 3 is true */
}
else
{
    /* executes when the none of the above condition is true */
}

4. Switch statement

Syntax:
switch(expression){
    case constant-expression :
        statement(s);
        break; /* optional */
    case constant-expression :
        statement(s);
        break; /* optional */
    /* you can have any number of case statements */
    default : /* Optional */
        statement(s);
    }



This video below show you examples about if, if-else, if-else-else-if, and switch statement in C++ programming language, which is developed with Microsoft Visual Studio 2010.



 You can also visit this video at www.youtube.com by click this link below.
http://www.youtube.com/watch?v=rZyafHd4Rws&feature=you http://www.youtube.com/watch?v=rZyafHd4Rws&feature=youtu.betu.be

No comments:

Post a Comment