SlideShare a Scribd company logo
Class 9 – Flow Control: Loops
Agenda Warm-up, Issues Controlling Flow with loops Quest: Defining and calling a Ruby method Assignment 6 Mid-term Exam
Warm-up and Issues Lateral Thinking Exercise Project Issues? Other Issues? Remaining Activities/ Work Plan Dates
Flow Control: Looping Iteration refers to the ability to repeat similar actions conditionally rather than requiring a user-entered signal to stop. Iterations may be loops using “while-end” or “until-end” or “for-end” or may be an array method using “.each” We will examine only loops tonight and save the “each” method for next week when we cover arrays.
Looping Scenarios Score Averager – what if you don’t know how many students there will be? A persistent converter
Looping Notation Pseudocode (sample) # get the number of rounds to complete # set a counter to value 0 # while the counter is less than the number of rounds # do some stuff here # increase the counter # end the loop
Looping Flowchart The Loop Decision implicit May evaluate true or false condition May use a counter to advance value start end Assignment name? Set counter = 0 Counter>10? Calculate Average Print Average Increment Counter Student Grade? Yes No
Looping Ruby Code While-end (a condition is true at the outset) var_type=“any wine” while var_type!=“exit” puts “what type of wine do you like (type exit to end)” var_type=gets.chomp puts ”Mmmmm. I like ” + var_type + “,too!” end
Looping Ruby Code Until-end (condition is false at the outset) var_type=“any wine” until var_type==“exit” puts “what type of wine do you like (type exit to end)” var_type=gets.chomp puts ”Mmmmm. I like ” + var_type + “,too!” end
Looping Ruby Code For-end (uses a range of values) for i in (1..12) puts i.to_s + “ o\’clock and all is well” end  for x in (“man”..”max”) puts x end
Exercise Sample: Can I do it until I wear glasses? Instructions: Develop a loop that will ask user to tell something about himself/herself Respond to each prompt in some way, e.g. “Interesting! Tell me more!” Continue to loop until the user says “I wear glasses” Then say “Bye!” and end program
Quest: Defining and Calling a Method What is a method? A function or operation that may be used several times in the application May perform a calculation on variables May return a value Must be at top of file in Ruby Why? Shortened code, consistent results Single code block to edit
Ruby: Declare/ Call Method Example def doFtoC (fVal) temp=fVal*9/5 + 32 return temp.round(2) end puts “enter fahrenheit temp” f_temp=gets.chomp.to_f puts “Celsius =” + doFtoC(f_temp).to_s
One last example Ruby – the wine connoisseur Your turn: Assignment 6 From Flowchart to Flow Control
Wrap-up Summary Iteration – repeating functions/operations Loops – a kind of iteration Methods: while, until, for Next Week Arrays, Intro Project 2  Assignment 6 due at start of class

More Related Content

PPTX
Adrenergic antagonist
PDF
Intro to Kubernetes
PPTX
Sample questions and answer for class 9 [Bangladesh]
PPTX
Class 9 & 10 Bangla 2nd Paper
PPTX
Class 9 & 10 bangla 2nd paper protibedon
PDF
10th class maths model question paper
PDF
Right form of verbs
PDF
ssc physics bangla প্রথম অধ্যায় পদার্থবিজ্ঞানের ক্রমবিকাশ
Adrenergic antagonist
Intro to Kubernetes
Sample questions and answer for class 9 [Bangladesh]
Class 9 & 10 Bangla 2nd Paper
Class 9 & 10 bangla 2nd paper protibedon
10th class maths model question paper
Right form of verbs
ssc physics bangla প্রথম অধ্যায় পদার্থবিজ্ঞানের ক্রমবিকাশ

Viewers also liked (20)

DOC
Live protibedon
DOC
Letter ---
DOC
Application in Bangla
PDF
2.5 গতির সমীকরণ equations of motion (ssc physics bangla)
PPTX
Sample questions and answers for class JSC students [Bangladesh]
PPTX
Accounting chapter-1
PPTX
গদ্য নবম ও দশম শ্রেণি বহিপীর ৩৫
PPTX
ssc physics bangla প্রথম অধ্যায় পদার্থবিজ্ঞানের ক্রমবিকাশ
PPTX
Class 7
PPTX
কবিতা নবম ও দশম শ্রেণি প্রাণ ২২
PPTX
Accounting chapter-2
PPTX
The statue of liberty for class 9/10 [Bangladesh]
PPTX
Class 9 & 10 bangla 2nd paper সন্ধি ২
PPTX
Class 9 & 10 bangla 2nd paper পদ প্রকরণ ২
PPTX
Class 9 & 10 bangla 2nd paper কারক ২
PDF
জীববিজ্ঞান শর্ট টেকনিক
PPTX
Class 9 & 10 lesson 2 class no 1 (cell)
PPTX
Math Lesson 10
PDF
Information and communication technology for hsc
PPTX
Beauty Of Bangladesh
Live protibedon
Letter ---
Application in Bangla
2.5 গতির সমীকরণ equations of motion (ssc physics bangla)
Sample questions and answers for class JSC students [Bangladesh]
Accounting chapter-1
গদ্য নবম ও দশম শ্রেণি বহিপীর ৩৫
ssc physics bangla প্রথম অধ্যায় পদার্থবিজ্ঞানের ক্রমবিকাশ
Class 7
কবিতা নবম ও দশম শ্রেণি প্রাণ ২২
Accounting chapter-2
The statue of liberty for class 9/10 [Bangladesh]
Class 9 & 10 bangla 2nd paper সন্ধি ২
Class 9 & 10 bangla 2nd paper পদ প্রকরণ ২
Class 9 & 10 bangla 2nd paper কারক ২
জীববিজ্ঞান শর্ট টেকনিক
Class 9 & 10 lesson 2 class no 1 (cell)
Math Lesson 10
Information and communication technology for hsc
Beauty Of Bangladesh
Ad

Similar to Class 9 Lecture Notes (20)

PDF
BDD style Unit Testing
PPTX
Going loopy - Introduction to Loops.pptx
PPT
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
DOCX
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
PPTX
CMSC 201 - Lec02 - Algorithmic Thinking.pptx
PPTX
Recursion, debugging in c
PDF
Programming in as3 the basics
PDF
Exception Handling: Designing Robust Software in Ruby
PPT
Ruby for C# Developers
PDF
Dutch PHP Conference 2013: Distilled
PPT
Node.js: CAMTA Presentation
PDF
ppts foe design and analysis of algorithm
PDF
Exception Handling: Designing Robust Software in Ruby (with presentation note)
PDF
02 Control Structures - Loops & Conditions
PPTX
CSE115 C Programming Introduction North south university
PPTX
While loop
PDF
Testing With Test::Class
PDF
Lecture 6.1 flow control selection
BDD style Unit Testing
Going loopy - Introduction to Loops.pptx
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
CMSC 201 - Lec02 - Algorithmic Thinking.pptx
Recursion, debugging in c
Programming in as3 the basics
Exception Handling: Designing Robust Software in Ruby
Ruby for C# Developers
Dutch PHP Conference 2013: Distilled
Node.js: CAMTA Presentation
ppts foe design and analysis of algorithm
Exception Handling: Designing Robust Software in Ruby (with presentation note)
02 Control Structures - Loops & Conditions
CSE115 C Programming Introduction North south university
While loop
Testing With Test::Class
Lecture 6.1 flow control selection
Ad

More from Stephen Parsons (19)

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
Class 8 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
Class 8 Lecture Notes
Deck Project Phase II

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PPT
Teaching material agriculture food technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Big Data Technologies - Introduction.pptx
Review of recent advances in non-invasive hemoglobin estimation
Digital-Transformation-Roadmap-for-Companies.pptx
sap open course for s4hana steps from ECC to s4
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Weekly Chronicles - August'25 Week I
Reach Out and Touch Someone: Haptics and Empathic Computing
Mobile App Security Testing_ A Comprehensive Guide.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Teaching material agriculture food technology
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Big Data Technologies - Introduction.pptx

Class 9 Lecture Notes

  • 1. Class 9 – Flow Control: Loops
  • 2. Agenda Warm-up, Issues Controlling Flow with loops Quest: Defining and calling a Ruby method Assignment 6 Mid-term Exam
  • 3. Warm-up and Issues Lateral Thinking Exercise Project Issues? Other Issues? Remaining Activities/ Work Plan Dates
  • 4. Flow Control: Looping Iteration refers to the ability to repeat similar actions conditionally rather than requiring a user-entered signal to stop. Iterations may be loops using “while-end” or “until-end” or “for-end” or may be an array method using “.each” We will examine only loops tonight and save the “each” method for next week when we cover arrays.
  • 5. Looping Scenarios Score Averager – what if you don’t know how many students there will be? A persistent converter
  • 6. Looping Notation Pseudocode (sample) # get the number of rounds to complete # set a counter to value 0 # while the counter is less than the number of rounds # do some stuff here # increase the counter # end the loop
  • 7. Looping Flowchart The Loop Decision implicit May evaluate true or false condition May use a counter to advance value start end Assignment name? Set counter = 0 Counter>10? Calculate Average Print Average Increment Counter Student Grade? Yes No
  • 8. Looping Ruby Code While-end (a condition is true at the outset) var_type=“any wine” while var_type!=“exit” puts “what type of wine do you like (type exit to end)” var_type=gets.chomp puts ”Mmmmm. I like ” + var_type + “,too!” end
  • 9. Looping Ruby Code Until-end (condition is false at the outset) var_type=“any wine” until var_type==“exit” puts “what type of wine do you like (type exit to end)” var_type=gets.chomp puts ”Mmmmm. I like ” + var_type + “,too!” end
  • 10. Looping Ruby Code For-end (uses a range of values) for i in (1..12) puts i.to_s + “ o\’clock and all is well” end for x in (“man”..”max”) puts x end
  • 11. Exercise Sample: Can I do it until I wear glasses? Instructions: Develop a loop that will ask user to tell something about himself/herself Respond to each prompt in some way, e.g. “Interesting! Tell me more!” Continue to loop until the user says “I wear glasses” Then say “Bye!” and end program
  • 12. Quest: Defining and Calling a Method What is a method? A function or operation that may be used several times in the application May perform a calculation on variables May return a value Must be at top of file in Ruby Why? Shortened code, consistent results Single code block to edit
  • 13. Ruby: Declare/ Call Method Example def doFtoC (fVal) temp=fVal*9/5 + 32 return temp.round(2) end puts “enter fahrenheit temp” f_temp=gets.chomp.to_f puts “Celsius =” + doFtoC(f_temp).to_s
  • 14. One last example Ruby – the wine connoisseur Your turn: Assignment 6 From Flowchart to Flow Control
  • 15. Wrap-up Summary Iteration – repeating functions/operations Loops – a kind of iteration Methods: while, until, for Next Week Arrays, Intro Project 2 Assignment 6 due at start of class