Ch5 - CSEB114: ogr amming Chapt er 5 St r uct ur ed Pr pr...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style 8/4/2008 prepared by NI, edited by CSEB 114: Principle of Programming Chapter 5: Structured Programming
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8/4/2008 prepared by NI, edited by Objectives In this chapter you will learn about: Sequential structure Selection structure if if … else switch Repetition Structure while do… while for
Background image of page 2
8/4/2008 prepared by NI, edited by Sequential Structure Statements are executed one by one until the end of the program is reached. A group of statements that executed sequentially which is usually grouped (bracketed) by { } is known as Compound Statement
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8/4/2008 prepared by NI, edited by Sequential Structure - example int main(void) { int count = 0; printf(“Count = %d\n”, count); count++; printf(“Count = %d\n”, count); count++; printf(“Count = %d\n”, count); count++; printf(“Count = %d\n”, count); count++; printf(“Count = %d\n”, count); return 0; }
Background image of page 4
8/4/2008 prepared by NI, edited by Selection Structure In selection structure, the program is executed based upon the given condition . Only instructions that satisfy the given condition are executed. There are 3 types of selection structure: if One alternative if…else Two alternatives nested if. .else Multiple alternatives
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8/4/2008 prepared by NI, edited by Selection structure:  if Syntax : if (condition) Statement; The statement is only executed if the condition is satisfied. Example: if (score >= 60) printf(“Pass!!\n”); § In the example above, the word “Pass!!” will only be printed out if score is larger than or equal to 60. If A condition is an expression that can return true or false (usually involving the use of an operator). Note that there is no semicolon (;) after the if statement. If there is one, that means the if statement and the printf() statement are 2 different statements and they will both get executed sequentially.
Background image of page 6
8/4/2008 prepared by NI, edited by Selection structure:  if… else Syntax : if (condition) statement1; else statement2; § If the condition is satisfied, statement1 will be executed. Otherwise, statement2 will get executed. Example : if (score >= 60) printf(“Pass!!\n”); else
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8/4/2008 prepared by NI, edited by Nested  if… else  statements A nested if…else statement is an if…else statement with another if…else statements inside it. Example : if (score >= 90) printf(“A\n”); else if (score >= 80) printf(“B\n”); else if (score >= 70) printf(“C\n”); else if (score >= 60) printf(“D\n”) else
Background image of page 8
8/4/2008 prepared by NI, edited by Plurality of Statements In the examples that we have seen so far, there is only one statement to be executed after the if statement.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/01/2011 for the course ECON 101 taught by Professor Yip during the Spring '11 term at Al-Quds University.

Page1 / 28

Ch5 - CSEB114: ogr amming Chapt er 5 St r uct ur ed Pr pr...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online