1 / 16

Selection

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 symbols Used to represent the flow of control of a computer program. Sample Flowchart. Basic Elements in Flowchart. Terminal Box.

lenka
Download Presentation

Selection

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Selection If

  2. 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

  3. Sample Flowchart

  4. Basic Elements in Flowchart Terminal Box Process Box Decision Box Flow line

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

  6. Terminator Box: Start and end of the flow 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. Meaning of Flowchart Elements

  7. 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

  8. Start Press Ctrl-Atl-Delete Turn on the computer Enter your password Wait until login screen appears End Relation Between Pseudo-code and Flowchart • Turn on the computer • Wait until login screen appears • Press Ctrl-Atl-Delete • Enter your password

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

  10. Start Stand Up Before 1:00 pm ? Good Morning Mr. Wong Good Afternoon Mr. Wong true false End Example

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

  12. If…then…else Statement • Syntax: • if <Boolean expression> • then <statement-1> • else <statement-2> • if, then, else are reserved words • Remember! no comma after statement-1 and before else • else statement can be omitted

  13. 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.

  14. 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

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

  16. 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

More Related