You are on page 1of 12

C AND C++ DECISION MAKING

Gerald L. Almodiel

CS331: Computer Organization, Architecture and


Assembly Language Programming

College of Computer Studies


AMA Computer University
Topics Outline
2

 If Statement

 If…Else Statement

 If…Else…If Statement

 Switch Statement

 Sample Programs

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


IF Statement
3

 If Statement
 An if statement consists of a boolean
expression followed by one or more
statements.
e.g.
if ( condition )
{
statement1;
statement2;
}

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


IF…Else Statement
4

 If…Else Statement
 An if statement can be followed by an
optional else statement, which executes
when the boolean expression is false.
e.g.
if ( condition)
statement1;
else
statement2;

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


IF…Else If Statement
5

 If…Else If Statement
 An if statement can be followed by multiple
if else statement, which executes when the
boolean expression is false.
e.g.
if ( condition )
statement1;
else if ( condition )
statement2;
else if ( condition )
statement 3;
:
:

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


Switch Statement
6

 Switch Statement
 A switch statement allows a variable to
be tested for equality against a list of
values.
e.g
switch( variable ){
case 1:
case 2:
default:
}

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


Sample Programs
7

If Statement

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


Sample Programs
8

If…Else Statement

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


Sample Programs
9

If…Else If Statement

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


Sample Programs
10

Switch Statement

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


Computer Organization, Architecture and Assembly
Language programming
11

ANY QUESTIONS ?

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014


12

~ FIN

CSCI6B : Computer Organization, Architecture and Assembly Language Programming 1/18/2014

You might also like