SlideShare a Scribd company logo
Class 8 – Conditional Logic
Agenda Lateral Thinking Warm-up Review Pseudocode & Flowchart Basics Discuss Conditions for Decisions Develop Notation for Conditions Develop Algorithms Incorporating Conditions Write Code to Accommodate Conditions Project Work
Pseudocode Review Pseudo-code is structured English that states the steps to the problem solution Statements are written in simple English Each instruction/step is written on a separate line Keywords and indentation are used to signify particular control structures Each set of instructions is written from top to bottom, with only one entry and one exit
Pseudocode in Programs Start Program # Prompt for Assignment Name # Get Assignment Name and assign to variable # Loop through Students 1-12 # prompt for grade # get grade and assign to variable # End Loop
Flow Chart Notation Review Terminal symbol- indicates the starting  or stopping point of logic: Input/Output symbol- reading or writing input/output: Process Symbol- any single process,  such as assigning a value or performing a calculation: Decision Symbol- comparisons/ T or F decision:  Flowlines- connect symbols in the flowchart:  arrow head suggests flow of data a straight line may be used to indicate a relationship
Sample FlowChart Pseudocode Start Program Prompt for assignment Set a counter Loop through grades Get student grade Increment counter End loop Calculate Average Print Average End Program start end Assignment name? Set counter = 1 Counter>10? Calculate Average Print Average Increment Counter Student Grade? Yes No
Conditions Example: Input: 2 integers Choose result type: sum, difference, product, quotient, modulus, or exponent Processing:? Conditional Operators Relational Logical
Relational Operators How does one item relate or compare to another? a>b a<b a=b a<>b a>=b a<=b Consider a=12 b=43 What is the effect on each of the conditions?
Relational Operators How does one item relate or compare to another? a>b a<b a=b a<>b a>=b a<=b Consider a=12 b=43 What is the effect on each of the conditions? false true false true false true
Logical Operators For complex conditions AND OR NOT A AND B A OR B NOT A A OR NOT B Consider a=Today is Tuesday b=It is Raining What is the effect on each of the conditions?
Exercise 8-1 Handout Evaluate Conditional Operators Excel solutions
Branching (Flow Control) Single Condition if - then  Dual Condition if – else – end if Multiple Condition select/ case
Notation - Single  Pseudocode START Prompt for input Get input x If  x>4 then Display “Hurray” End if END Flowchart start end x>4? get x Print “Hurray” T F
Notation - Dual Pseudocode START Prompt for input Get input x If  x>4 then Display “Hurray” else Display “Sorry” End if END Flowchart start end x>4? Get x Print “Hurray” Print “Sorry” T F
Notation – Multiple (Pseudocode) START Prompt for input Get input x Evaluate (Case for x) where x= 3 print “close” where x= 2 print “very close” where x= 1 print “bang on” where x is anything else print “not even close” End case END
Notation – Multiple (Flowchart) start end X=3 Print “very close” T F eval x X=2 Get x X=1 Print “close” Print “bang on” Print “not even close” T T F F
Case versus Nested IF START Prompt for input Get input x CASE FOR X case x= 3   print “close” case x= 2   print “very close” case x= 1   print “bang on” case other   print “not even close” END CASE END START Prompt for input Get input x if x= 3   print “close” else   if x= 2   print “very close”   else   if x= 1   print “bang on”   else   print “not even close”   end if end if end if END
Exercise 8-2 Handout Develop Pseudocode and Flowchart
Conditional Code in Ruby Conditionals Relational a>b, a<b, a<=b, a>=b, a==b, a!=b Logical && (AND), || (OR), ! (NOT) Requires parenthesis E.g. if  ( A>6 && C!=“Math” ) … Ruby Demo
Quest: Project Work Rubric  1. Application Interface is simple and functional (6)  2. Application functions all work with appropriate and intuitive prompts (8)  3. Application presents an attractive output and then exits cleanly without any errors. (6)  ( hint: pseudocode will allow me to substitute for any lost marks )
Project Work Total value=20% Due by start of class next week Prefer you zip the file and email to me Otherwise I’ll copy it to my flash disk at start of class
Summary Review Notation Pseudocode and flowcharts Conditional logic Relational operators Logical operators Branching/ Flow Control Ruby language Project evaluation
Questions? Enjoy the holiday Lest we forget…

More Related Content

PPT
Class 9 Lecture Notes
PPT
PPT
Computer Programming, Loops using Java
PPTX
Debugging
PPT
The secret of Functional Programming revealed!
PPTX
pseudocode and Flowchart
PPTX
Pseudocode
PPTX
Conditional statements
Class 9 Lecture Notes
Computer Programming, Loops using Java
Debugging
The secret of Functional Programming revealed!
pseudocode and Flowchart
Pseudocode
Conditional statements

What's hot (20)

PPTX
Error handling and debugging in vb
PDF
Function procedure c6 c7
PDF
Error handling and debugging
PPTX
Pseudocode
PPTX
Introduction to flowchart
PPT
Unit 3 Foc
PPTX
Algorithm and psuedocode
PPT
Programing Fundamental
PPT
Pseudocode algorithim flowchart
PPTX
Debugging in .Net
PDF
Pseudocode By ZAK
PPT
Algorithmsandflowcharts1
PPSX
Problem solving and design
PPT
CPP10 - Debugging
PPT
Programming fundamentals lecture 1&2
DOCX
Oop lab assignment 01
PDF
The pseudocode
PPTX
Advantages Over Conventional Error Handling in OOP
PDF
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
PPT
Algorithms
Error handling and debugging in vb
Function procedure c6 c7
Error handling and debugging
Pseudocode
Introduction to flowchart
Unit 3 Foc
Algorithm and psuedocode
Programing Fundamental
Pseudocode algorithim flowchart
Debugging in .Net
Pseudocode By ZAK
Algorithmsandflowcharts1
Problem solving and design
CPP10 - Debugging
Programming fundamentals lecture 1&2
Oop lab assignment 01
The pseudocode
Advantages Over Conventional Error Handling in OOP
CMIS 102 HANDS-ON LAB WEEK 6 OVERVIEW THIS HANDS-ON LAB ALLOWS YOU TO FOLLOW ...
Algorithms
Ad

Viewers also liked (20)

PDF
Jsc latest math complete solution guide tanbircox
PPTX
Sample questions and answers for class JSC students [Bangladesh]
PPTX
Class 8 math lesson 2 (munafa)
PDF
Right form of verbs
PPT
Class 8 english 1st paper filling in a form lesson-2 and going through immig...
PDF
Magic method of fill in the blanks by tanbircox
PDF
Health benefits and medicinal properties of bd fruits
PPTX
Sample questions and answer for class 9 [Bangladesh]
PPTX
Rules for filling correct form of the verb
PDF
Current affairs a to z for all competitive exams
PPT
Class 8 english announcements on board 2 lesson 6
PPTX
Class 8 english lesson 1 health
PPT
Class 8 english lesson 2 the history of the wheel
PPTX
Class 8 english lesson 2 the ama divers
PPT
Class 8 english destination
PPT
Class 8 english lesson 4 our ethnic friend-2
Jsc latest math complete solution guide tanbircox
Sample questions and answers for class JSC students [Bangladesh]
Class 8 math lesson 2 (munafa)
Right form of verbs
Class 8 english 1st paper filling in a form lesson-2 and going through immig...
Magic method of fill in the blanks by tanbircox
Health benefits and medicinal properties of bd fruits
Sample questions and answer for class 9 [Bangladesh]
Rules for filling correct form of the verb
Current affairs a to z for all competitive exams
Class 8 english announcements on board 2 lesson 6
Class 8 english lesson 1 health
Class 8 english lesson 2 the history of the wheel
Class 8 english lesson 2 the ama divers
Class 8 english destination
Class 8 english lesson 4 our ethnic friend-2
Ad

Similar to Class 8 Lecture Notes (20)

PDF
AlgorithmAndFlowChart.pdf
PPT
Basic Slides on Algorithms and Flowcharts
PPT
Lect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
PPT
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
PPT
Lect1 - Algorithms-and-Flowchart-ppt.ppt
PPT
Lect1-Algorithms-and-Flowchart-ppt (1).ppt
PPT
Lecture1-Algorithms-and-Flowchart-ppt.ppt
PPT
Lecture1-Algorithms-and-Flowchart-ppt.ppt
PPT
Lect1-Algorithms-and-Flowchart PPT presentation
PPT
Copy of dti2143/dam31303 chap 1 problem solving and program design
PPT
Algorithms and Flowchart usages in C laguage
PPTX
Algorithms and flowcharts
PPT
Programming algorithms and flowchart.ppt
PPT
Algorithms and Flowchart.ppt
PPT
learn computer science.ppt
PPSX
Complete C++ programming Language Course
PPTX
Fundamentals of Programming Lecture #1.pptx
PPT
Introduction To Programming
PPTX
Programming Fundamentals
PPT
our c prog work
AlgorithmAndFlowChart.pdf
Basic Slides on Algorithms and Flowcharts
Lect1-Detailed description aboutAlgorithms-and-Flowchart.ppt
Lecture1-Algorithms-and-Flowcharts-ppt.ppt
Lect1 - Algorithms-and-Flowchart-ppt.ppt
Lect1-Algorithms-and-Flowchart-ppt (1).ppt
Lecture1-Algorithms-and-Flowchart-ppt.ppt
Lecture1-Algorithms-and-Flowchart-ppt.ppt
Lect1-Algorithms-and-Flowchart PPT presentation
Copy of dti2143/dam31303 chap 1 problem solving and program design
Algorithms and Flowchart usages in C laguage
Algorithms and flowcharts
Programming algorithms and flowchart.ppt
Algorithms and Flowchart.ppt
learn computer science.ppt
Complete C++ programming Language Course
Fundamentals of Programming Lecture #1.pptx
Introduction To Programming
Programming Fundamentals
our c prog work

More from Stephen Parsons (18)

PPTX
Atlantic Woodworkers Website Strategy
PPTX
Chairs Report to LSCRS 2012 AGM
PPT
Class 10 Arrays
PPT
Program Renewal for NSCC Schools 2010-11
PPT
Class 7 lecture notes
PPTX
Class 6a ruby math
PPTX
Class 6 truth tables and boolean math
PPTX
Class 5 - Set Theory and Venn Diagrams
PPTX
Class 4 IPO and Intro to Ruby
PPTX
Class 3 Binary & Hexadecimal
PPTX
Class 2 Math I
PPT
Class 1 introduction to logic & problem solving
PPTX
Portfolio Of A Community
PPT
Cause & effect analysis part 2
PPT
Cause & effect analysis part 1
PPT
Class 11 lecture notes
PPT
Class 10 Lecture Notes
PPT
Deck Project Phase II
Atlantic Woodworkers Website Strategy
Chairs Report to LSCRS 2012 AGM
Class 10 Arrays
Program Renewal for NSCC Schools 2010-11
Class 7 lecture notes
Class 6a ruby math
Class 6 truth tables and boolean math
Class 5 - Set Theory and Venn Diagrams
Class 4 IPO and Intro to Ruby
Class 3 Binary & Hexadecimal
Class 2 Math I
Class 1 introduction to logic & problem solving
Portfolio Of A Community
Cause & effect analysis part 2
Cause & effect analysis part 1
Class 11 lecture notes
Class 10 Lecture Notes
Deck Project Phase II

Class 8 Lecture Notes

  • 1. Class 8 – Conditional Logic
  • 2. Agenda Lateral Thinking Warm-up Review Pseudocode & Flowchart Basics Discuss Conditions for Decisions Develop Notation for Conditions Develop Algorithms Incorporating Conditions Write Code to Accommodate Conditions Project Work
  • 3. Pseudocode Review Pseudo-code is structured English that states the steps to the problem solution Statements are written in simple English Each instruction/step is written on a separate line Keywords and indentation are used to signify particular control structures Each set of instructions is written from top to bottom, with only one entry and one exit
  • 4. Pseudocode in Programs Start Program # Prompt for Assignment Name # Get Assignment Name and assign to variable # Loop through Students 1-12 # prompt for grade # get grade and assign to variable # End Loop
  • 5. Flow Chart Notation Review Terminal symbol- indicates the starting or stopping point of logic: Input/Output symbol- reading or writing input/output: Process Symbol- any single process, such as assigning a value or performing a calculation: Decision Symbol- comparisons/ T or F decision: Flowlines- connect symbols in the flowchart: arrow head suggests flow of data a straight line may be used to indicate a relationship
  • 6. Sample FlowChart Pseudocode Start Program Prompt for assignment Set a counter Loop through grades Get student grade Increment counter End loop Calculate Average Print Average End Program start end Assignment name? Set counter = 1 Counter>10? Calculate Average Print Average Increment Counter Student Grade? Yes No
  • 7. Conditions Example: Input: 2 integers Choose result type: sum, difference, product, quotient, modulus, or exponent Processing:? Conditional Operators Relational Logical
  • 8. Relational Operators How does one item relate or compare to another? a>b a<b a=b a<>b a>=b a<=b Consider a=12 b=43 What is the effect on each of the conditions?
  • 9. Relational Operators How does one item relate or compare to another? a>b a<b a=b a<>b a>=b a<=b Consider a=12 b=43 What is the effect on each of the conditions? false true false true false true
  • 10. Logical Operators For complex conditions AND OR NOT A AND B A OR B NOT A A OR NOT B Consider a=Today is Tuesday b=It is Raining What is the effect on each of the conditions?
  • 11. Exercise 8-1 Handout Evaluate Conditional Operators Excel solutions
  • 12. Branching (Flow Control) Single Condition if - then Dual Condition if – else – end if Multiple Condition select/ case
  • 13. Notation - Single Pseudocode START Prompt for input Get input x If x>4 then Display “Hurray” End if END Flowchart start end x>4? get x Print “Hurray” T F
  • 14. Notation - Dual Pseudocode START Prompt for input Get input x If x>4 then Display “Hurray” else Display “Sorry” End if END Flowchart start end x>4? Get x Print “Hurray” Print “Sorry” T F
  • 15. Notation – Multiple (Pseudocode) START Prompt for input Get input x Evaluate (Case for x) where x= 3 print “close” where x= 2 print “very close” where x= 1 print “bang on” where x is anything else print “not even close” End case END
  • 16. Notation – Multiple (Flowchart) start end X=3 Print “very close” T F eval x X=2 Get x X=1 Print “close” Print “bang on” Print “not even close” T T F F
  • 17. Case versus Nested IF START Prompt for input Get input x CASE FOR X case x= 3 print “close” case x= 2 print “very close” case x= 1 print “bang on” case other print “not even close” END CASE END START Prompt for input Get input x if x= 3 print “close” else if x= 2 print “very close” else if x= 1 print “bang on” else print “not even close” end if end if end if END
  • 18. Exercise 8-2 Handout Develop Pseudocode and Flowchart
  • 19. Conditional Code in Ruby Conditionals Relational a>b, a<b, a<=b, a>=b, a==b, a!=b Logical && (AND), || (OR), ! (NOT) Requires parenthesis E.g. if ( A>6 && C!=“Math” ) … Ruby Demo
  • 20. Quest: Project Work Rubric 1. Application Interface is simple and functional (6) 2. Application functions all work with appropriate and intuitive prompts (8) 3. Application presents an attractive output and then exits cleanly without any errors. (6) ( hint: pseudocode will allow me to substitute for any lost marks )
  • 21. Project Work Total value=20% Due by start of class next week Prefer you zip the file and email to me Otherwise I’ll copy it to my flash disk at start of class
  • 22. Summary Review Notation Pseudocode and flowcharts Conditional logic Relational operators Logical operators Branching/ Flow Control Ruby language Project evaluation
  • 23. Questions? Enjoy the holiday Lest we forget…

Editor's Notes

  • #4: Programmatic Algorithms will be interested in efficiency and effectiveness – elegance