1 / 44

Selection Statement

. Outline. 2. Boolean expressionif statementnested if statementswitch case statementFlowchart. Boolean Expression. OperatorsComparisonEqual ==Not equal !=Less <Greater >Less than or equal to <=Greater than or equal to >=. BooleanAnd

rudolph
Download Presentation

Selection Statement

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 Statement Thanachat Thanomkulabut

    2. Outline 2 Boolean expression if statement nested if statement switch case statement Flowchart

    3. Boolean Expression Operators Comparison Equal == Not equal != Less < Greater > Less than or equal to <= Greater than or equal to >= Boolean And && Or || Not ! 3 ! Exclamation mark! Exclamation mark

    4. Boolean Expression Example From the equation: X2+9X+10 = 0 How can we check that value of X is the answer for above equation? Condition: Is value Y even number? 4

    5. Example: Boolean Expressions double x = 4.0; Expression Value x < 5.0 ___________ x > 5.0 ___________ x <= 5.0 ___________ 5.0 == x ___________ x != 5.0 ___________ (3!=4)&&(7<5) ___________ (4>4)||(5<=10) ___________ 5

    6. Outline 6 Boolean expression if statement nested if statement switch case statement Flowchart

    7. if statement Execute the specific statement when the ”condition” becomes true Syntax: 7

    8. if statement 8

    9. if statement 9

    10. 10 if statement example BMI (Body Mass Index)

    11. if statement example

    12. Test I Selfish Ratio

    13. if…else… statement If condition is true ? execute statement1 If condition is false ? execute statement2 Syntax:

    14. if…else… statement 14

    15. if…else… statement 15

    16. if…else… statement example 16 Write the program which check input number. input : integer number output : message to inform that number is odd or even.

    17. if…else… statement example 17

    18. Test II 18 Write the program which find the value of function input : number output :

    19. Outline 19 Boolean expression if statement nested if statement switch case statement FlowChart

    20. Nested if statement

    21. Nested if statement

    22. Nested if statement

    23. Nested if statement

    24. Exercise 1: Separated IF (simple) if (eaten==true) {Console.WriteLine(“ I’ve already eaten”);} else {Console.WriteLine(“ I’ve not eat yet”);} if (like_noodle==true) {Console.WriteLine(“I like noodle”);} else {Console.WriteLine(“I don’t like noodle”);}

    25. if (like_noodle==true) {Console.WriteLine(“I like noodle”);} else { Console.WriteLine(“I don’t like noodle”); if (like_friedrice==true) {Console.WriteLine(“I like friedrice”);} else {Console.WriteLine(“I don’t like friedrice”);} } Exercise 2: Related two IF (full version)

    26. if (like_noodle==true) {Console.WriteLine(“I like noodle”);} else if (like_friedrice==true) {Console.WriteLine(“I like friedrice”);} else {Console.WriteLine(“I don’t like friedrice”);} Exercise 2: Related two IF (short version)

    27. if (like_noodle==true) {Console.WriteLine(“I like noodle”); if (love_SenYai==true) {Console.WriteLine(“I love Sen-Yai”);} else {Console.WriteLine(“I don’t love Sen-Yai”);} } else if (like_friedrice==true) {Console.WriteLine(“I like fried rice”);} else {Console.WriteLine(“I don’t like fried rice”);} Exercise 3: Nested two IF (short version)

    28. Nested if statement example 28 Write the program which show student’s grade input : score of student output :

    29. Test III 29 Write the program which calculation value of following function input : value of x output : function value of x according with ...

    30. Outline 30 Boolean expression if statement nested if statement switch case statement Flowchart

    31. switch…case statement For selecting a statement where its label corresponds to the value of the switch expression.

    32. 32 Example: switch-case (1)

    33. Test III 33 Write the program which show numbers of day in each months input : Abbreviation of months output : numbers of day in each months

    34. 34 Example: switch-case (2)

    35. 35 Example: switch-case (3)

    36. 36 Example: switch-case (4)

    37. Convert switch-case to if else

    38. Outline 38 Boolean expression if statement nested if statement switch case statement Flowchart

    39. Flowchart Symbols Overview Graphical representation ??????????? = diamond??????????? = diamond

    40. Program Flowchart Example

    41. if statement flowchart

    42. if statement flowchart 42

    43. Test IV 43 Write flow chart which accord to following program

    44. Any question?

More Related