Karel J Robot Chapter 6.

Slides:



Advertisements
Similar presentations
Chapter 11 Lists and iteration. This chapter discusses n Managing collections of objects. n The fundamental container object is called a list. n Fundamental.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Karel – Chapter 6 Instructions That Repeat
Selected Advanced Topics Chapter 7 and 8
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
CS0004: Introduction to Programming Repetition – Do Loops.
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Software Development Study Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
If Statements Sections 1.25, Control Structures o All code thus far executes every line of code sequentially o We want to be able to repeat,
Midterm Exam 2 75 points 1 min per point Allocate time proportionate to points Closed book Chapters 6-9 Look at exercises.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 5 – Recursive Funtions From Deitel’s “C” Book 5.13Recursion 5.14Example Using Recursion: The Fibonacci.
Multiple Choice Solutions True/False a c b e d   T F.
1 karel_part5_loops Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit (known)
Sequential & Object oriented Programming
Institute for Personal Robots in Education (IPRE)‏ CSC 170 Computing: Science and Creativity.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
Chapter 04 Control Statements: Part II. OBJECTIVES In this part you will learn: if…else Double-Selection Statement. while Repetition Statement.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
Chapter 9 Interfaces and Polymorphism. 9.1 Reusing Code An interface is a collection of related methods whose headers are provided without implementation.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises 1 Xiang Lian The University of Texas Rio Grande Valley.
1 Ch. 6 Iteration (Loops) Loops repeat a set of instructions Two types of loops: –Definite loops ( for ) perform instructions explicit number of times.
Repetition Statements while and do while loops
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
Repetition Statements (Loops) The do while Loop The last iteration structure in C++ is the do while loop. A do while loop repeats a statement or.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com Day 4.
Computer Science 209 Software Development Inheritance and Composition.
Murach, Chapter 5. Common Control Structures Selection: The IF statement Case: The Select Case statement Iteration: Loops 9/28/20082.
Karel J. Robot Chapter 6 Instructions That Repeat.
Interfaces Describe what classes should do, without specifying how they should do it Not a class, but a set of requirements for classes that want to conform.
Today’s lecture Review of chapter 8 Go over examples.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Karel J Robot Chapter 5.
1 Chapter 5 Karel J Robot 2 Chapter 5 Chapter 5 Conditional Statements Flavor 1: if ( ) { } For now: these are method invocations (see next slide)
Karel J. Robot Chapter 6 Instructions That Repeat.
Decision Making: while loops and Boolean Logic. While Loops A while loop is a structure within ROBOTC which allows a section of code to be repeated as.
Sensor Information: while loops and Boolean Logic.
Exam 2 Review.
Chapter 4 Repetition Statements (loops)
Chapter 3: Decisions and Loops
10.3 Details of Recursion.
Loops We have already seen instances where a robot needs to repeat instructions to perform a task turnRight(); moveMile(); Harvesting beepers in a field.
Polymorphism and Observers
Karel J Robot Chapter 6.
Chapter 5: Loops and Files.
Expressions and Control Flow in JavaScript
Chapter 10 Thinking in Objects
Decision statements. - They can use logic to arrive at desired results
Loops October 10, 2017.
While Loops and If-Else Structures
The University of Texas – Pan American
Chapter 9 Control Structures.
Iteration: Beyond the Basic PERFORM
Iteration: Beyond the Basic PERFORM
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II – Exercises UTPA – Fall 2012 This set of slides is revised from.
Chapter 7 Polymorphism.
Chapter 8: More on the Repetition Structure
Unit 1 Lab14 & Lab15.
CH5 – Conditional Statements
slides created by Alyssa Harding
Repetition Statements (Loops) - 2
Iteration (Loops) Loops repeat a set of instructions
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Flow of Control Flow of control is the order in which a program performs actions. Up to this point, the order has been sequential. A branching statement.
How to allow the program to know when to stop a loop.
G6DICP - Lecture 5 Control Structures.
Presentation transcript:

Karel J Robot Chapter 6

What we have learned so far: Classes vs objects (e.g. UrRobot vs. karel) Parts of a class (constructor, method) Classifying errors Polymorphism (extending classes) Abstract classes and interfaces Conditionals Booleans, logical operators

For Loop Loops – code that repeats some action either a finite or infinite amount of times Also called iteratives 2 types of loops Definate loops (for) perform instructions an explicit number of times Indefinate loops (while) perform instructions until a certain test fails

For Loop Example: public void move(int numMoves){..} Which loop do we want? Structure of a for loop: For(int x = 0; x<10; x++) { <repeated code>} For loop needs 3 things: An initializer – can be initialized in for loop, or before A boolean test – loop while run until the test is false An operation – typically an incrementer

For Loop How many times will each for-loop run? for(x=0; x<10; x++) { …} for(x=0; x<=10; x++){…} for(x=10; x>0; x--){…} for(x=2; x>=14; x+=2) {…} Feel free to program the code and test it Let’s keep to a standard form: Start: x=0; Test: x<#; //don’t use <=; the # will represent how many times the loop runs Increment by x++;

While Loop Aside: the For-Loop takes on different forms, but the previous slides demonstrate its simplest form For Loop – good for looping when you know how many times you need to repeat When you need to program a loop that runs until a certain event happens…. Use a while loop

While Loop Form: while(<test>) { <do instructions>} Examples: while(!nextToABeeper()) {..} while(x>10){…} while(2>=4){…} The test can be any boolean outcome The actions in the loop should make progress to change the boolean test (to avoid an infinite loop)

Relational Operators Review ->Logical operators: &&, ||, ! Relational Operators are used for comparison >, >=, < <=, ==, != Note: = and == are not the same thing! = is the assignment operator… == is ‘equal to’

Student work Read chapter 6 (up to page 161) Program the Guard robot on page 162 to the end of the chapter Problem set 6 #1,2,3,8,14,16,24,34