Chapter 9.1: Lists Lists are often called by another name in other programming languages – arrays.

Slides:



Advertisements
Similar presentations
As you come in…  Sign in (in back) and pick up  Badge  Name Card – write your first name LARGELY on back  Log in:  Launch/Start Alice  Any questions?
Advertisements

CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Repeating Actions While and For Loops
Complexity Analysis (Part I)
16-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
CS 106 Introduction to Computer Science I 02 / 12 / 2007 Instructor: Michael Eckmann.
Alice in Action with Java
Loops – While, Do, For Repetition Statements Introduction to Arrays
Slides prepared by Rose Williams, Binghamton University Chapter 3 Flow of Control Loops in Java.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
CHAPTER 2 ANALYSIS OF ALGORITHMS Part 2. 2 Running time of Basic operations Basic operations do not depend on the size of input, their running time is.
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
Loops Repetition Statements. Repetition statements allow us to execute a statement multiple times Often they are referred to as loops Like conditional.
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
ECE122 L9: While loops March 1, 2007 ECE 122 Engineering Problem Solving with Java Lecture 9 While Loops.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Chapter 4: Control Structures II
Games and Simulations O-O Programming in Java The Walker School
While Loops and Do Loops. Suppose you wanted to repeat the same code over and over again? System.out.println(“text”); System.out.println(“text”); System.out.println(“text”);
01-Intro-Object-Oriented-Prog-Alice1 Barb Ericson Georgia Institute of Technology Aug 2009 Introduction to Object-Oriented Programming in Alice.
Chapter 6: (Expressions,) Functions, and If/Else First we had animations – They “ran”/played the same way every time. – Neat, but a bit boring Then we.
REPETITION STRUCTURES. Topics Introduction to Repetition Structures The while Loop: a Condition- Controlled Loop The for Loop: a Count-Controlled Loop.
Lecture 5: Finishing 4.3 and onto 5.1 Preparing for the Midterm: Written Explanations Technology and Society Assignment (5% - 3 in term) – How does the.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
Python November 28, Unit 9+. Local and Global Variables There are two main types of variables in Python: local and global –The explanation of local and.
 The general subject of comparing objects, or object references, can be introduced concretely with strings.  Recall that String is a class, and so strings.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
CPS120 Introduction to Computer Science Iteration (Looping)
Chapter 4: Classes, Objects, and Parameters 4.1 World-Level methods.
Algorithms and Algorithm Analysis The “fun” stuff.
CPS120: Introduction to Computer Science Decision Making in Programs.
© 2006 Pearson Education 1 More Operators  To round out our knowledge of Java operators, let's examine a few more  In particular, we will examine the.
Current Assignments Homework 2 is available and is due in three days (June 19th). Project 1 due in 6 days (June 23 rd ) Write a binomial root solver using.
(1) Unit Testing and Test Planning CS2110: SW Development Methods These slides design for use in lab. They supplement more complete slides used in lecture.
Week 3 - Wednesday.  What did we talk about last time?  Other C features  sizeof, const  ASCII table  printf() format strings  Bitwise operations.
Overview of Java Loops By: Reid Hunter. What Is A Loop? A loop is a series of commands that will continue to repeat over and over again until a condition.
Today’s Announcements Assignment 8 is due Project 2 is due 7/27/04 We will be skipping chapter 22 Test 3 (chapters 18-21) will be on 7/29/04 Tip of the.
Research Topics in Computational Science. Agenda Survey Overview.
Selection Statements. Introduction Today we learn more about learn to make decisions in Turing ▫Nested if statements, ▫case statements.
CPS120 Introduction to Computer Science Iteration (Looping)
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
Intermediate 2 Computing Unit 2 - Software Development.
More Python!. Lists, Variables with more than one value Variables can point to more than one value at a time. The simplest way to do this is with a List.
Using Lists Games Programming in Scratch. Games Programming in Scratch Extension – Using Lists Learning Objectives Create a temporary data store (list)
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 5 Repetition Structures.
CHAPTER 14 Classes, Objects, and Games XNA Game Studio 4.0.
Lists Alice. Collections In some animations, several objects must perform the same actions Example: A marching band, where the band members are performing.
CS 31 Discussion, Week 5 Faisal Alquaddoomi, Office Hours: BH 2432, MW 4:30-6:30pm, F 12:00-1:00pm (today)
While loops. Iteration We’ve seen many places where repetition is necessary in a problem. We’ve been using the for loop for that purpose For loops are.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
LOOPS CHAPTER Topics  Four Types of Loops –while –do…while –for –foreach  Jump Statements in Loops –break –continue 2.
Running Records 201 Britt Humphries, EdS. Literacy Instructional Facilitator Fort Smith Public Schools brittsliteracyworkshops.pbworks.com.
Programming in Java (COP 2250) Lecture 12 & 13 Chengyong Yang Fall, 2005.
Lecture Wed Week 7 Midterm grades on gradesource – Graded out of 26 (free point) – Question 1 confusing – everyone gets full points – Solutions posted.
Loop Design What goes into coding a loop. Considerations for Loop Design ● There are basically two kinds of loops: ● Those that form some accumulated.
1 Quiz Show Programming Terms. 2 Alice - 3D Virtual Programming Vocabulary Quiz Board Chapter 1 Chapter 2a Chapter 2b Chapter 3 Chapter 4 $100 $200 $300.
Alice Development Environment. Which area contains our “program” (set of instructions)? D AB C.
ENCAPSULATION. WHY ENCAPSULATE? So far, the objects we have designed have all of their methods and variables visible to any part of the program that has.
11 Making Decisions in a Program Session 2.3. Session Overview  Introduce the idea of an algorithm  Show how a program can make logical decisions based.
CS 106 Introduction to Computer Science I 02 / 15 / 2008 Instructor: Michael Eckmann.
2-D Lists Taken from notes by Dr. Neil Moore
Repeating Instructions And Advance collection
Algorithm Discovery and Design
Coding Concepts (Basics)
Lecture Mon Week 8 Tech and Society #2 Due Tuesday 11:59pm!
Topics Introduction to Repetition Structures
Presentation transcript:

Chapter 9.1: Lists Lists are often called by another name in other programming languages – arrays.

Suppose there is a list of Customers (people waiting in line). You want to serve each customer one at a time, so each one should walk into the store one at a time. A.Use a DoTogether tile B.Use a DoInOrder tile C.Use a ForAllTogether tile D.Use a ForAllInOrder tile

Which of the following types can be used in a list? A.Rockette B.Rockette’s Thighs C.Rockette’s Hips D.All of the Above

If I declare a list thusly, and use a ForAllInOrder tile, what order do the rockettes kick? Order Arockette rockette2 rockette3 Brockette rockette3 rockette2 CYou can’t be sure DNone of the above

Old SuperBowl Commercial has three frogs talk But what they are advertising we isn’t “ahem” a school topic – So let’s modify it.

Three Frogs Three frogs, together they say – Frog 1 (on left) “Hear No Evil” – Frog 2 (in middle) “See No Evil” – Frog 3 (on right) “Speak No Evil” That’s hard – let’s start with – Three frogs talk in order left to right – All of them say the same thing: Hello – Like this:

What does this code do?

A.The frogs talk in order left to right B.The frogs talk in backwards order (right to left) C.Each frog talks, but the order depends

It ALWAYS goes in the order you make your list in

Let’s assume I remake my list like this (L to R):

What if I want the frogs to say Hello (left to right) 5 times? A.Make a counted loop run five times INSIDE (as the inner loop) the ForAllInOrder loop B.Make a counted loop run five times with the ForAllInOrder loop INSIDE (as the inner loop)

Predict: What would this code do? ???

By the way… you can make a list out of different kinds of objects Do the wave with different “People” objects Make different types of flowers grow And out of other things…

Problem: Each frog should say something different… Hear no evil See no evil Speak no evil

What programming construct would you use? A.An if statement inside the For all in order B.A counted loop inside the For all in order C.An if statement before the For all in order D.A counted loop outside the For all in order E.I don’ t know…

There are (at least) two possible solutions… What is the BEST explanation of why is one better than the other? A.Option 1 is better because it is shorter B.Option 1 is better because it does the least number of “checks” (or boolean condition evaluations) C.Option 2 is better because it makes clear exactly what the “checks” (or boolean condition evaluations) are D.Option 2 is better because it has a regular structure with empty “else” portions

A)Shorter B)Least Boolean Checks C) Clear Boolean Checks D) Regular Structure with Empty “else”es

Remember this… “Good” programs aren’t (always) the ones that – Make it easiest on the programmer – Are easiest for humans to read – Require least amount of effort from programmer Instead they are (usually) the ones that – Require least computing work (by computer) – Are easiest to adapt to new situations Methods and parameters come in here

There’s an EVEN BETTER way to write this program! Think about this… – What if we had… A list of froggies – Some number of frogs that want to talk A list of words – Exactly the same “number” of Strings to be “said” by each of those frogs… – How can we make a program that will make each frog say a specific word In ONLY 2 LINES OF CODE?!?!?

Let’s make the beetles do a more complicated dance… Like this:

Which structure would you want? A.One ForAllInOrder loop B.One ForAllInOrder loop with an if statement inside C.One if statement with a ForAllTogether inside D.None of the above

Does this code correctly implement our intended behavior? A.Yes B.No C.I don’t know And WHY!

What is new about this code? Nested “for all” loops A loop that “iterates” over all items in a list – Inside that is another loop that goes over all the items in a list – In this case, happen to be the same list Wow, you can do complicated things now…

There are 4 beetles, how many times is this instruction executed? A.4 B.12 C.16 D.48 E.I don’t know

Parameters to methods: We can do better now!

How would we do our “new” solo (with backup)