Nesting. Abstraction & Nesting. Example. if x is less than y output x is smaller else output y is smaller. CS256 Computer Science I Kevin Sahr, PhD
|
|
- Merilyn Briggs
- 6 years ago
- Views:
Transcription
1 CS256 Computer Science I Kevin Sahr, PhD Lecture 19: Nested Conditionals and Loops 1 Nesting remember that conditional statements and loops contain single statements (or single block statements) this statement can itself be a conditional or loop a conditional or loop that occurs inside another conditional or loop is called a nested conditional or loop 2 Abstraction & Nesting abstraction is the key to writing complicated nested constructs view each entire nested conditional or loop as a single abstracted unit relative to what it is nested in 3 EX: pseudocode that outputs which of two numbers is smaller: x is less than y output x is smaller output y is smaller problem: what x and y are equal? will need to use a nested conditional 4
2 Abstract Pseudocode recall that we can write pseudocode at dferent levels of abstraction what matters is that you can get from the pseudocode to Java source code once we understand the - on the previous slide, we can abstract that pseudocode as: output the smaller of x and y 5 Pseudocode we can then write pseudocode to handle the case when x and y are equal: x is equal to y output equal output the smaller of x and y 6 Building the Code start with the code for the equality case: (x == y) Output.showMessage( equal ); output the smaller of x and y 7 Code now substitute in the code for the -clause unit: (x == y) Output.showMessage( equal ); (x < y) Output.showMessage( x is smaller ); Output.showMessage( y is smaller ); note no s could use but not necessary, since the nested - is a single statement relative to the outer - 8
3 EX: given a numeric grade ( ), output the corresponding letter grade 9 (grade >= 8.0) (grade >= 7.0) (grade >= 6.0) this code is hard to read recall that Java doesn t care about whitespace, so we can reformat it to make our meaning clearer 10 (grade >= 8.0) (grade >= 7.0) (grade >= 6.0) 11 (grade >= 8.0) (grade >= 7.0) (grade >= 6.0) 12
4 (grade >= 8.0) (grade >= 7.0) (grade >= 6.0) 13 (grade >= 8.0) (grade >= 7.0) (grade >= 6.0) see Grade.java for a complete program 14 ( 2) EX: our code from earlier (x == y) Output.showMessage( equal ); (x < y) Output.showMessage( x is smaller ); Output.showMessage( y is smaller ); 15 ( 2) should be formatted: (x == y) Output.showMessage( equal ); (x < y) Output.showMessage( x is smaller ); Output.showMessage( y is smaller ); 16
5 input word problem: Write a program that calculates and outputs the areas of circles with user-input radii. For each circle, give the user as many chances as needed to enter a positive radius. Classy each area as big (greater than 100), medium (less than or equal to 100 and greater than 50), or small (less than or equal to 50). let s begin by breaking this down into smaller chunks that must be accomplished 17 word problem: Write a program that calculates and outputs the areas of circles with user-input radii. For each circle, give the user as many chances as needed to enter a positive radius. Classy each area as big (greater than 100), medium (less than or equal to 100 and greater than 50), or small (less than or equal to 50). we note that the highlighted phrase is an instance of the algorithm: positive radius we have detailed pseudocode for this algorithm (see last lecture) 18 word problem: Write a program that calculates and outputs the areas of circles with user-input radii. For each circle, give the user as many chances as needed to enter a positive radius. Classy each area as big (greater than 100), medium (less than or equal to 100 and greater than 50), or small (less than or equal to 50). let s write an algorithm named calculate area for the highlighted portion: area = 3.14 * radius * radius output area 19 word problem: Write a program that calculates and outputs the areas of circles with user-input radii. For each circle, give the user as many chances as needed to enter a positive radius. Classy each area as big (greater than 100), medium (less than or equal to 100 and greater than 50), or small (less than or equal to 50). note that classying the area will be a nested construct so let s abstract-out the details of that part by writing an algorithm for just that part 20
6 Pseudocode for Algorithm classy area area is greater than 100 output BIG area is greater than 50 output MEDIUM output SMALL 21 we now have three abstract algorithms: input positive radius calculate area classy area now we can write the entire program pseudocode, ignoring the details of these abstract sub-algorithms note that our word problem indicates that the program must handle multiple circles; we can use either: a counter-controlled loop, or a sentinel loop we choose a counter-controlled loop 22 Word Problem Program Pseudocode input positive #-of-circles do #-of-circles times input positive radius calculate area classy area now we just need to substitute in the code for each sub-unit of pseudocode see Circles2.java for the complete source code 23 Nested Loops note that this program contains an input validation loop nested inside of a counter-controlled loop when working with nested loops it is especially important to think of the inner loop as a single unit, independent of the outer loop the inner loop will execute completely every time the outer loop executes once 24
7 Nested Loops EX: How many times will "A" be output? count1 = 0; while (count1 < 10) count2 = 0; while (count2 < 20) count2 = count2 + 1; count1 = count1 + 1; We can use abstraction to understand this code Nested Loops Note that the inner loop is a countercontrolled loop count1 = 0; while (count1 < 10) count2 = 0; while (count2 < 20) count2 = count2 + 1; count1 = count1 + 1; Nested Loops let s replace the inner loop with our abstract counter-controlled loop pseudocode count1 = 0; while (count1 < 10) output A 20 times count1 = count1 + 1; Nested Loops the outer loop is also a counter-controlled loop, so let s replace that as well repeat 10 times output A 20 times How many times will "A" be output? 10 * 20 =
8 Lecture 19 Vocabulary nested conditional nested loop 29
Flow of Control. Conditional Statements. Conditional Statements. CS256 Computer Science I Kevin Sahr, PhD. Lecture 15: The If-Statement
CS256 Computer Science I Kevin Sahr, PhD Lecture 15: The If-Statement 1 Flow of Control the order of statement execution default is top-to-bottom 2 Conditional Statements we can change the flow of control
More informationConstants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous
CS256 Computer Science I Kevin Sahr, PhD Lecture 25: Miscellaneous 1 main Method Arguments recall the method header of the main method note the argument list public static void main (String [] args) we
More informationLecture 7 Tao Wang 1
Lecture 7 Tao Wang 1 Objectives In this chapter, you will learn about: Interactive loop break and continue do-while for loop Common programming errors Scientists, Third Edition 2 while Loops while statement
More informationInformation Science 1
Topics covered Information Science 1 Fundamental Programming Constructs (1) Week 11 Terms and concepts from Week 10 Flow of control and conditional statements Selection structures if statement switch statement
More informationInformation Science 1
Information Science 1 Fundamental Programming Constructs (1) Week 11 College of Information Science and Engineering Ritsumeikan University Topics covered l Terms and concepts from Week 10 l Flow of control
More informationRepetition Structures
Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements
More informationCondition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.
Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes
More informationPrograms as Models. Procedural Paradigm. Class Methods. CS256 Computer Science I Kevin Sahr, PhD. Lecture 11: Objects
CS256 Computer Science I Kevin Sahr, PhD Lecture 11: Objects 1 Programs as Models remember: we write programs to solve realworld problems programs act as models of the real-world problem to be solved one
More informationMore Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types
datatype CS200: Computer Science I Module 14 More Data Types Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 More Data Types in addition to the data types double and int we
More informationStepwise Refinement. Lecture 12 COP 3014 Spring February 2, 2017
Stepwise Refinement Lecture 12 COP 3014 Spring 2017 February 2, 2017 Top-Down Stepwise Refinement Top down stepwise refinement is a useful problem-solving technique that is good for coming up with an algorithm.
More informationCS110D: PROGRAMMING LANGUAGE I
CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 5&6: Loops Lecture Contents Why loops?? While loops for loops do while loops Nested control structures Motivation Suppose that you need
More informationComparing Data. Comparing Floating Point Values. Comparing Float Values. CS257 Computer Science I Kevin Sahr, PhD
1 CS257 Computer Science I Kevin Sahr, PhD Lecture 6: Comparing Data and Complex Boolean Expressions Comparing Data 2 When comparing data it's important to understand the nuances of certain data types
More informationClass API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects
CS200: Computer Science I Module 19 More Objects Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 Class API a class API can contain three different types of methods: 1. constructors
More informationLecture 5 Tao Wang 1
Lecture 5 Tao Wang 1 Objectives In this chapter, you will learn about: Selection criteria Relational operators Logical operators The if-else statement Nested if statements C++ for Engineers and Scientists,
More informationDr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions.
1.0 Expressions Dr. Scheme evaluates expressions so we will start by using the interactions window and asking Dr. Scheme to evaluate some expressions. Numbers are examples of primitive expressions, meaning
More informationCS125 : Introduction to Computer Science. Lecture Notes #6 Compound Statements, Scope, and Advanced Conditionals
CS125 : Introduction to Computer Science Lecture Notes #6 Compound Statements, Scope, and Advanced Conditionals c 2005, 2004, 2003, 2002, 2001, 2000 Jason Zych 1 Lecture 6 : Compound Statements, Scope,
More informationCS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise
CS61A Notes Week 6: Scheme1, Data Directed Programming You Are Scheme and don t let anyone tell you otherwise If you re not already crazy about Scheme (and I m sure you are), then here s something to get
More informationITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University
ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 08: Control Statements Readings: Chapter 6 Control Statements and Their Types A control
More informationINTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from
INTRODUCTION TO C++ PROGRAM CONTROL Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Repetition Statement for while do.. while break and continue
More informationProfessor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors
First Python Program Professor Hugh C. Lauer CS-1004 Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction to Computer Science, 2 nd edition, by
More informationSME 1013 Programming for Engineers
SME 1013 Programming for Engineers Programming Concepts by: Mohamed Hussein compliments to: Assoc. Prof. Dr. Mohd Shafiek Yaacob Stages of Program Development Logic errors Input? Formula? Special Cases?
More informationPIC 10A. Review for Midterm I
PIC 10A Review for Midterm I Midterm I Friday, May 1, 2.00-2.50pm. Try to show up 5 min early so we can start on time. Exam will cover all material up to and including todays lecture. (Only topics that
More informationProgram Development. Chapter 3: Program Statements. Program Statements. Requirements. Java Software Solutions for AP* Computer Science A 2nd Edition
Chapter 3: Program Statements Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition Program Development The creation of software involves four basic activities: establishing
More informationChapter 3: Program Statements
Chapter 3: Program Statements Presentation slides for Java Software Solutions for AP* Computer Science 3rd Edition by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by
More informationProgram Development. Java Program Statements. Design. Requirements. Testing. Implementation
Program Development Java Program Statements Selim Aksoy Bilkent University Department of Computer Engineering saksoy@cs.bilkent.edu.tr The creation of software involves four basic activities: establishing
More informationFinal Examination Semester 3 / Year 2010
Southern College Kolej Selatan 南方学院 Final Examination Semester 3 / Year 2010 COURSE : PROGRAMMING LOGIC AND DESIGN COURSE CODE : CCIS1003 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE LECTURER : LIM
More informationProgramming Language. Machine Code. CS200: Computer Science I. Module 3 Programming Languages
CS200: Computer Science I Module 3 Programming Languages Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 Programming Language a language for writing programs that tell the computer
More informationProgramming Lecture 4
Five-Minute Review 1. What are classes and objects? What is a class hierarchy? 2. What is an expression? A term? 3. What is a variable declaration? 4. What is an assignment? What is precedence? 5. What
More informationMobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02
Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.
More information#4: While Loop Reading: Chapter3
CS 130R: Programming in Python #4: While Loop Reading: Chapter3 Contents Constants While loop Infinite loop Break Continue Constants Similar to variables, but their names are with capital letters and their
More informationObject Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance
CS257 Computer Science I Kevin Sahr, PhD Lecture 10: Inheritance 1 Object Oriented Features For a programming language to be called object oriented it should support the following features: 1. objects:
More informationChapter 4 Introduction to Control Statements
Introduction to Control Statements Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives 2 How do you use the increment and decrement operators? What are the standard math methods?
More informationControl Structures in Java if-else and switch
Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification
More informationDefinite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting
Unit 2, Part 2 Definite Loops Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting Let's say that we're using a variable i to count the number of times that
More informationChapter Four: Loops. Slides by Evan Gallagher. C++ for Everyone by Cay Horstmann Copyright 2012 by John Wiley & Sons. All rights reserved
Chapter Four: Loops Slides by Evan Gallagher The Three Loops in C++ C++ has these three looping statements: while for do The while Loop while (condition) { statements } The condition is some kind of test
More informationWeek 2. Relational Operators. Block or compound statement. if/else. Branching & Looping. Gaddis: Chapters 4 & 5. CS 5301 Spring 2018.
Week 2 Branching & Looping Gaddis: Chapters 4 & 5 CS 5301 Spring 2018 Jill Seaman 1 Relational Operators l relational operators (result is bool): == Equal to (do not use =)!= Not equal to > Greater than
More informationCS 483. Jana Kosecka CS Dept Eng. Building
CS 483 Jana Kosecka CS Dept. 4444 Eng. Building kosecka@gmu.edu Course Info Course webpage: from the syllabus on http://cs.gmu.edu/courses/ Information you will find course syllabus, time table office
More informationIntroduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop
Introduction to Programming in C Department of Computer Science and Engineering Lecture No. #16 Loops: Matrix Using Nested for Loop In this section, we will use the, for loop to code of the matrix problem.
More informationSolving Problems Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3
Solving Problems Flow Control in C++ CS 16: Solving Problems with Computers I Lecture #3 Ziad Matni Dept. of Computer Science, UCSB A Word About Registration for CS16 FOR THOSE OF YOU NOT YET REGISTERED:
More informationFundamentals of Programming (Python) Control Structures. Sina Sajadmanesh Sharif University of Technology Fall 2017
Fundamentals of Programming (Python) Control Structures Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Python: How to Program 1 st Edition Outline 1. Control Structures
More informationSTUDENT OUTLINE. Lesson 8: Structured Programming, Control Structures, if-else Statements, Pseudocode
STUDENT OUTLINE Lesson 8: Structured Programming, Control Structures, if- Statements, Pseudocode INTRODUCTION: This lesson is the first of four covering the standard control structures of a high-level
More informationSorting. Bubble Sort. Selection Sort
Sorting In this class we will consider three sorting algorithms, that is, algorithms that will take as input an array of items, and then rearrange (sort) those items in increasing order within the array.
More informationSTUDENT LESSON A12 Iterations
STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of
More informationLECTURE 04 MAKING DECISIONS
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 04 MAKING DECISIONS
More informationWriteup for first project of CMSC 420: Data Structures Section 0102, Summer Theme: Threaded AVL Trees
Writeup for first project of CMSC 420: Data Structures Section 0102, Summer 2017 Theme: Threaded AVL Trees Handout date: 06-01 On-time deadline: 06-09, 11:59pm Late deadline (30% penalty): 06-11, 11:59pm
More informationPrinciples of Computer Science I
Principles of Computer Science I Prof. Nadeem Abdul Hamid CSC 120A - Fall 2004 Lecture Unit 7 Review Chapter 4 Boolean data type and operators (&&,,) Selection control flow structure if, if-else, nested
More informationDecision Structures. Lesson 03 MIT 11053, Fundamentals of Programming
Decision Structures Lesson 03 MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz M.Sc. in IS (SLIIT), PGD in IS (SLIIT), BBA (Hons.) Spl. In IS (SEUSL), MIEEE, Microsoft Certified Professional
More informationLoops (while and for)
Loops (while and for) CSE 1310 Introduction to Computers and Programming Alexandra Stefan 1 Motivation Was there any program we did (class or hw) where you wanted to repeat an action? 2 Motivation Name
More informationProblem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur
Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 15 Branching : IF ELSE Statement We are looking
More information8/27/2016. ECE 120: Introduction to Computing. Graphical Illustration of Modular Arithmetic. Representations Must be Unambiguous
University of Illinois at Urbana-Champaign Dept. of Electrical and Computer Engineering ECE 120: Introduction to Computing Signed Integers and 2 s Complement Strategy: Use Common Hardware for Two Representations
More informationC Programming for Engineers Structured Program
C Programming for Engineers Structured Program ICEN 360 Spring 2017 Prof. Dola Saha 1 Switch Statement Ø Used to select one of several alternatives Ø useful when the selection is based on the value of
More informationLOOPS. Repetition using the while statement
1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while
More information*Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN
PowerPoint Slides adapted from *Starting Out with C++: From Control Structures through Objects, 7/E* by *Tony Gaddis* Copyright 2012 Pearson Education Inc. COMPUTER PROGRAMMING LECTURE 05 LOOPS IMRAN IHSAN
More informationCS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction
CS/COE 1501 cs.pitt.edu/~bill/1501/ Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge and may not be sold
More informationOutline. Program development cycle. Algorithms development and representation. Examples.
Outline Program development cycle. Algorithms development and representation. Examples. 1 Program Development Cycle Program development cycle steps: Problem definition. Problem analysis (understanding).
More information10-2 Circles. Warm Up Lesson Presentation Lesson Quiz. Holt Algebra2 2
10-2 Circles Warm Up Lesson Presentation Lesson Quiz Holt Algebra2 2 Warm Up Find the slope of the line that connects each pair of points. 1. (5, 7) and ( 1, 6) 1 6 2. (3, 4) and ( 4, 3) 1 Warm Up Find
More informationDecision Structures. Lecture 3 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz
Decision Structures Lecture 3 MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Chapter Topics o Relational Operators o The if Statement o The if-else Statement o Nested if statements o The if-else-if
More informationThe data in the table are arranged into 12 rows and 12 columns. The process of printing them out can be expressed in a pseudocode algorithm as
Control structures in Java are statements that contain statements. In particular, control structures can contain control structures. You've already seen several examples of if statements inside loops,
More informationMath 291: Lecture 4. Dr. Fagerstrom. Minnesota State University Moorhead web.mnstate.edu/fagerstrom
Math 291: Lecture 4 Dr. Fagerstrom Minnesota State University Moorhead web.mnstate.edu/fagerstrom fagerstrom@mnstate.edu February 8, 2018 Dr. Fagerstrom (MSUM) Math 291: Lecture 4 February 8, 2018 1 /
More informationLoops / Repetition Statements. There are three loop constructs in C. Example 2: Grade of several students. Example 1: Fixing Bad Keyboard Input
Loops / Repetition Statements Repetition s allow us to execute a multiple times Often they are referred to as loops C has three kinds of repetition s: the while loop the for loop the do loop The programmer
More informationObject Class. EX: LightSwitch Class. Basic Class Concepts: Parts. CS257 Computer Science II Kevin Sahr, PhD. Lecture 5: Writing Object Classes
1 CS257 Computer Science II Kevin Sahr, PhD Lecture 5: Writing Object Classes Object Class 2 objects are the basic building blocks of programs in Object Oriented Programming (OOP) languages objects consist
More informationMathematics 134 Calculus 2 With Fundamentals Exam 2 Answers/Solutions for Sample Questions March 2, 2018
Sample Exam Questions Mathematics 1 Calculus 2 With Fundamentals Exam 2 Answers/Solutions for Sample Questions March 2, 218 Disclaimer: The actual exam questions may be organized differently and ask questions
More informationVirtual Memory. CSCI 315 Operating Systems Design Department of Computer Science
Virtual Memory CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture have been largely based on those from an earlier edition of the course text Operating
More informationWarm Up Problem. Write any equivalent MIPS program corresponding to the following code: int wain ( int a, int b){ int c = a + b; return c*a; }
Warm Up Problem Write any equivalent MIPS program corresponding to the following code: int wain ( int a, int b){ int c = a + b; return c*a; } CS 241 Lecture 17 Type Checking Continued and Code Generation
More informationMicrosoft Visual Basic 2005: Reloaded
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 4 Making Decisions in a Program Objectives After studying this chapter, you should be able to: Include the selection structure in pseudocode
More informationProgramming Lecture 4
Five-Minute Review 1. What are classes and objects? What is a class hierarchy? 2. What is an expression? A term? 3. What is a variable declaration? 4. What is an assignment? What is precedence? 5. What
More informationCS 302: Introduction to Programming in Java. Lecture 9
1 CS 302: Introduction to Programming in Java Lecture 9 2 No class on Wednesday in Observance of Fourth of July 3 Announcement Programming Assignment #1 Due 11:59pm Sunday July 8 th Follow style and commenting
More informationRepetition Structures II
Lecture 9 Repetition Structures II For and do-while loops CptS 121 Summer 2016 Armen Abnousi Types of Control Structures Sequential All programs that we have written so far The statements inside a pair
More informationRational Numbers on the Coordinate Plane. 6.NS.C.6c
Rational Numbers on the Coordinate Plane 6.NS.C.6c Copy all slides into your composition notebook. Lesson 14 Ordered Pairs Objective: I can use ordered pairs to locate points on the coordinate plane. Guiding
More informationTop-Down Program Development
Top-Down Program Development Top-down development is a way of thinking when you try to solve a programming problem It involves starting with the entire problem, and breaking it down into more manageable
More informationChapter 11. Analysis of Algorithms
Chapter 11 Analysis of Algorithms Chapter Scope Efficiency goals The concept of algorithm analysis Big-Oh notation The concept of asymptotic complexity Comparing various growth functions Java Foundations,
More informationLecture Transcript While and Do While Statements in C++
Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some
More informationwhile (condition) { body_statements; for (initialization; condition; update) { body_statements;
ITEC 136 Business Programming Concepts Week 01, Part 01 Overview 1 Week 7 Overview Week 6 review Four parts to every loop Initialization Condition Body Update Pre-test loops: condition is evaluated before
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationThis is the basis for the programming concept called a loop statement
Chapter 4 Think back to any very difficult quantitative problem that you had to solve in some science class How long did it take? How many times did you solve it? What if you had millions of data points
More informationChapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Chapter 3 More Flow of Control Overview 3.1 Using Boolean Expressions 3.2 Multiway Branches 3.3 More about C++ Loop Statements 3.4 Designing Loops Slide 3-3 Flow Of Control Flow of control refers to the
More informationInstruction-Level Parallelism Dynamic Branch Prediction. Reducing Branch Penalties
Instruction-Level Parallelism Dynamic Branch Prediction CS448 1 Reducing Branch Penalties Last chapter static schemes Move branch calculation earlier in pipeline Static branch prediction Always taken,
More informationCS/COE 1501
CS/COE 1501 www.cs.pitt.edu/~nlf4/cs1501/ Introduction Meta-notes These notes are intended for use by students in CS1501 at the University of Pittsburgh. They are provided free of charge and may not be
More informationWithout savetrees. An Example Document
Without savetrees An Example Document Leslie Lamport January 21, 1994 This is an example input file. Comparing it with the output it generates can show you how to produce a simple document of your own.
More informationCS112 Lecture: Repetition Statements
CS112 Lecture: Repetition Statements Objectives: Last revised 2/18/05 1. To explain the general form of the java while loop 2. To introduce and motivate the java do.. while loop 3. To explain the general
More informationYou will need the following items: scissors, plate, 5 different colored pencils, protractor, paper to answer questions
Radian measure task You will need the following items: scissors, plate, 5 different colored pencils, protractor, paper to answer questions Instructions will follow on each slide. Feb 19 10:33 AM Step 1
More informationCS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016
CS 31: Intro to Systems Binary Arithmetic Kevin Webb Swarthmore College January 26, 2016 Reading Quiz Unsigned Integers Suppose we had one byte Can represent 2 8 (256) values If unsigned (strictly non-negative):
More informationCMSC 330: Organization of Programming Languages. OCaml Expressions and Functions
CMSC 330: Organization of Programming Languages OCaml Expressions and Functions CMSC330 Spring 2018 1 Lecture Presentation Style Our focus: semantics and idioms for OCaml Semantics is what the language
More informationMEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1. March 28-30, 2007
MEHMET YAYAN - İSMAİL HAKKI ÖZTÜRK CS101/SEC.-2 CLASS NOTES 1 March 28-30, 2007 if Single-Selection Statement The conditional statement in Java has the form if (condition) statement The condition must
More informationChapter 1: Foundations for Algebra
Chapter 1: Foundations for Algebra Dear Family, The student will follow the order of operations, a set of rules that standardize how to simplify expressions. Order of Operations 1. Perform operations within
More informationAgent Design Example Problems State Spaces. Searching: Intro. CPSC 322 Search 1. Textbook Searching: Intro CPSC 322 Search 1, Slide 1
Searching: Intro CPSC 322 Search 1 Textbook 3.0 3.3 Searching: Intro CPSC 322 Search 1, Slide 1 Lecture Overview 1 Agent Design 2 Example Problems 3 State Spaces Searching: Intro CPSC 322 Search 1, Slide
More informationComputer Systems C S Cynthia Lee Today s materials adapted from Kevin Webb at Swarthmore College
Computer Systems C S 0 7 Cynthia Lee Today s materials adapted from Kevin Webb at Swarthmore College 2 Today s Topics TODAY S LECTURE: Caching ANNOUNCEMENTS: Assign6 & Assign7 due Friday! 6 & 7 NO late
More informationChapter 4: Conditionals and Loops
Chapter 4: Conditionals and Loops CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 4: Conditionals and Loops CS 121 1 / 69 Chapter 4 Topics Flow
More informationPROGRAM EFFICIENCY & COMPLEXITY ANALYSIS
Lecture 03-04 PROGRAM EFFICIENCY & COMPLEXITY ANALYSIS By: Dr. Zahoor Jan 1 ALGORITHM DEFINITION A finite set of statements that guarantees an optimal solution in finite interval of time 2 GOOD ALGORITHMS?
More informationCS164: Midterm I. Fall 2003
CS164: Midterm I Fall 2003 Please read all instructions (including these) carefully. Write your name, login, and circle the time of your section. Read each question carefully and think about what s being
More informationCS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer
CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer Assigned: Thursday, September 16, 2004 Due: Tuesday, September 28, 2004, at 11:59pm September 16, 2004 1 Introduction Overview In this
More informationProblem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur
Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to
More informationCS112 Lecture: Loops
CS112 Lecture: Loops Objectives: Last revised 3/11/08 1. To introduce some while loop patterns 2. To introduce and motivate the java do.. while loop 3. To review the general form of the java for loop.
More informationConditionals and Loops
Conditionals and Loops Conditionals and Loops Now we will examine programming statements that allow us to: make decisions repeat processing steps in a loop Chapter 5 focuses on: boolean expressions conditional
More informationComputer Aided Engineering Design Prof. Anupam Saxena Department of Mechanical Engineering Indian Institute of Technology, Kanpur.
(Refer Slide Time: 00:28) Computer Aided Engineering Design Prof. Anupam Saxena Department of Mechanical Engineering Indian Institute of Technology, Kanpur Lecture - 6 Hello, this is lecture number 6 of
More informationSeparable Kernels and Edge Detection
Separable Kernels and Edge Detection CS1230 Disclaimer: For Filter, using separable kernels is optional. It makes your implementation faster, but if you can t get it to work, that s totally fine! Just
More informationRemember, to manage anything, we need to measure it. So, how do we compare two implementations? ArrayBag vs. LinkedBag Which is more efficient?
CS706 Intro to Object Oriented Dev II - Spring 04 Announcements Week 4 Program due Two Weeks! Lab 3-4 required completion this week First web-cat submission Material Evaluation of efficiency Time Analysis
More informationOther Loop Options EXAMPLE
C++ 14 By EXAMPLE Other Loop Options Now that you have mastered the looping constructs, you should learn some loop-related statements. This chapter teaches the concepts of timing loops, which enable you
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 06 / 11 / 2015 Instructor: Michael Eckmann Today s Topics Comments and/or Questions? Sorting Searching Michael Eckmann - Skidmore College - CS 106 - Summer 2015
More informationLECTURE 5 Control Structures Part 2
LECTURE 5 Control Structures Part 2 REPETITION STATEMENTS Repetition statements are called loops, and are used to repeat the same code multiple times in succession. The number of repetitions is based on
More information