1 / 16

Flowchart If – Then – Else

Flowchart If – Then – Else . อนันต์ ผลเพิ่ม Anan Phonphoem anan@cpe.ku.ac.th. Outline. Flowcharts IF – THEN – ELSE . Boolean Expression. Two possible values: True, False Relation Operator = , < , > , <> , <= , >= Boolean Operator AND , OR , NOT.

tareq
Download Presentation

Flowchart If – Then – Else

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. FlowchartIf – Then – Else อนันต์ ผลเพิ่ม Anan Phonphoem anan@cpe.ku.ac.th

  2. Outline • Flowcharts • IF – THEN – ELSE

  3. Boolean Expression • Two possible values: True, False • Relation Operator • = , < , > , <> , <= , >= • Boolean Operator • AND , OR , NOT 15 = 34 False 15.05 < 17 True 34 < > 34.00002 True

  4. Precedence rules for arithmetic operators • ( ) parentheses • Unary + and – • *, / , DIV , MOD • + – • If equal precedence, left to right Examples -a+j/-w = (-a) + (j / (-w)) C*23/6+23mod2 = ((C*23)/6) + (23 mod 2)

  5. Precedence rules for Boolean Operators • ( ) parentheses • NOT • and • Or • < , <= ,> , <= , = , <> • If equal precedence, left to right Examples (count <= 10) AND (Sum <= Limit) ORNOT Stop

  6. Flowcharts • Graphical representation of algorithm Terminator Process Input/output Decision Connector Flow line

  7. Flowchart example Start Read width Read length Total := width + length If total < > 0 No Yes Write total End

  8. condition False True Statement IF – THEN IF condition THEN statement

  9. IF – Then (sum1.pas) Program summation1; Var Sum, number : integer; Begin Sum := 10; Write (‘Please input a number’); Readln(number); if number < 0 then number := 0; Sum := Sum + number; writeln (‘Sum =‘, Sum) End.

  10. condition True False Statement1 Statement2 IF – THEN – ELSE IF condition THEN statement 1 ELSE statement 2

  11. IF – Then – Else (sum2.pas) Program summation2; Var Sum, number : integer; Begin Sum := 10; Write (‘Please input a number’); Readln(number); if number < 0 then number := 0; else number := 20; Sum := Sum + number; writeln (‘Sum =‘, Sum) End.

  12. condition1 False True condition2 True False Statement1 Statement2 Statement3 Nested Logic IF cond1 THEN statement1 ELSE IFcond2 THEN Statement2 ELSE statement3

  13. Nested Logic (Sum3.pas) Begin Sum := 10; Write (‘Please input a number’); Readln(number); if number > 0 then number := number +1; if number > 5 then number := 5; else number := 20; Sum := Sum + number; writeln (‘Sum =‘, Sum) End.

  14. Nested Logic (sum4.pas) Begin Sum := 10; Write (‘Please input a number’); Readln(number); if number > 0 then begin number := number +1; if number > 5 then number := 5; End else number := 20; Sum := Sum + number; writeln (‘Sum =‘, Sum) End.

  15. Case Case expression of const_value1 : statement1; const_value2 : statement2; const_value3 : statement3; Else statement4; End;

  16. Case Example Readln (number); Case number of 1,2,3 : writeln(‘small’); 4,5,6 : writeln(‘medium’); 7,8 : writeln (‘large’); End;

More Related