Presentation is loading. Please wait.

Presentation is loading. Please wait.

Selection If Flowchart A diagram that shows step-by-step progression through a procedure or system especially using connecting lines and a set of conventional.

Similar presentations


Presentation on theme: "Selection If Flowchart A diagram that shows step-by-step progression through a procedure or system especially using connecting lines and a set of conventional."— Presentation transcript:

1

2 Selection If

3 Flowchart A diagram that shows step-by-step progression through a procedure or system especially using connecting lines and a set of conventional symbols Used to represent the flow of control of a computer program

4 Sample Flowchart

5 Basic Elements in Flowchart Terminal BoxProcess Box Decision BoxFlow line

6 Another Sample Turn on the computer Wait until login screen appears Press Ctrl-Atl-Delete Enter your password Flow of control of turn on and login windows NT Start End

7 Meaning of Flowchart Elements Process Box: Action that will be taken Flow Line: The direction of line indicates the next state Decision Box: A true-or-false decision, the next state depends on the result of the decision. Terminator Box: Start and end of the flow

8 Relation Between Pseudo-code and Flowchart Both pseudo-code and flowchart descript the steps and flow to solve a problem You can convert a pseudo-code to flowchart and vice versa

9 Relation Between Pseudo-code and Flowchart Turn on the computer Wait until login screen appears Press Ctrl-Atl-Delete Enter your password Start End 1. Turn on the computer 2. Wait until login screen appears 3. Press Ctrl-Atl- Delete 4. Enter your password

10 Decision Box One of the elements in flowchart Contains a true or false statement The next state depends on the value of the statement

11 Example Start Before 1:00 pm ? Stand Up Good Morning Mr. Wong Good Afternoon Mr. Wong truefalse End

12 Pseudo-code Version Stand-up If the time is before 1:00 pm Say “Good morning Mr. Wong” Else, say “Good afternoon Mr. Wong” Start Before 1:00 pm ? Stand Up Good Morning Mr. Wong Good Afternoon Mr. Wong truefalse End

13 If…then…else Statement Syntax: if then else if, then, else are reserved words Remember! no comma after statement-1 and before else else statement can be omitted

14 Example program positive; var input : integer; begin write ( ‘Please enter a number: ‘ ); readln ( input ); if input >= 0 then writeln ( ‘It is a positive number’ ) else writeln ( ‘It is a negative number’ ) end.

15 Compound statements Compound statement means one or more statements bracketed by begin and end The statement part itself is also a compound statement The then part and else part of if…then…else statement should contain one statement only If you need more then one statement in any of these parts, you have to use compound statement

16 Example if x > 0 then begin y := x + 1; writeln ( x ); end ……

17 Nested if statements if statement inside the then part or the else part of another if statement You are reminded to write program with proper indentation


Download ppt "Selection If Flowchart A diagram that shows step-by-step progression through a procedure or system especially using connecting lines and a set of conventional."

Similar presentations


Ads by Google