 There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there.

Slides:



Advertisements
Similar presentations
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Advertisements

Microsoft® Small Basic
While Loops. Challenge: ● Ask the user a simple math questions ● Continue asking the question until the user gets it right.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Matlab tutorial course Exercises 4:. Exercises – for loops Download the scripts loops_example.m and if_else_example.m, run the code Download the function,
Floyd, Digital Fundamentals, 10 th ed EET 2259 Unit 5 Loops  Read Bishop, Sections 5.1 and 5.2.  Lab #5 and Homework #5 due next week.  Exam #1 next.
A Christmas Scratch game
This game is loosely based on the Whack-A- Mole arcade game.  Each game starts with 45 seconds of play.  Moles randomly pop out of holes on the landscape.
Mrs. Chapman. Tabs (Block Categories) Commands Available to use Script Area where you type your code Sprite Stage All sprites in this project.
Scratch Programming Session 9 of 10 Review elements to use in stories, games, etc.
CS 106 Introduction to Computer Science I 02 / 11 / 2008 Instructor: Michael Eckmann.
Scripting Languages Perl Chapter #4 Subroutines. Writing your own Functions Functions is a programming language serve tow purposes: –They allow you to.
Copyright © Texas Education Agency, Computer Programming For Loops.
PROGRAMMING In Lesson 5. RECAP  Complete the starter activity.
Probability Models Chapter 17.
Summer Computing Workshop. Session 4 Loops  At the heart of their functionality, loops enable blocks of code to be executed more than once  Loops represent.
How to make Space Invaders
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
THE BIG PICTURE. How does JavaScript interact with the browser?
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
 Make sure you are subscribed to announcements on Moodle.  Activity 4 will be due 48hrs after your lab ends.
Using MIT Scratch for Programming and Control Exercise 6 – Creating a Scratch Packman Year 9 ICT Autumn Term 2007.
 Review  Created our own motion block called “draw square”  Used script to create a square with side lengths of 100 steps.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
1 CSCI N201 Programming Concepts and Database 9 – Loops Lingma Acheson Department of Computer and Information Science, IUPUI.
Fish Chomp. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions.
CONTROL FLOW The order in which blocks are executed is called the “control flow” of the script So far all our scripts have just executed blocks in the.
ITP © Ron Poet Lecture 7 1 Repetition. ITP © Ron Poet Lecture 7 2 Easing Repetitive Tasks  Many computing task are repetitive.  Checking all known foods.
Conditional Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Designing While Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Comparing and Ordering Numbers How do we know which number is largest?
Iteration. Iteration: Review  If you wanted to display all the numbers from 1 to 1000, you wouldn’t want to do this, would you? Start display 1 display.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
Maths quiz KS 2: Use sequence in programs. Today we are learning about: Programs & Selection ●I can explain what selection is ●I can write a program using.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
Today's Ninja Challenge: Write Your First Computer Game!
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Microsoft® Small Basic Conditions and Loops Estimated time to complete this lesson: 2 hours.
Repetition In today’s lesson we will look at: why you would want to repeat things in a program different ways of repeating things creating loops in Just.
CS161 Introduction to Computer Science
Understanding the Geometric Shape Code
Scratch: iteration / repetition / loops
Warm-up Program Use the same method as your first fortune cookie project and write a program that reads in a string from the user and, at random, will.
Unit 2 Getting Started With
Diamond Hunt Mock Programming Project.
Starter Write a program that asks the user if it is raining today.
Iterations Programming Condition Controlled Loops (WHILE Loop)
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Scratch Programming Intro
Standard Algorithms Input validation Finding the minimum
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Repetition Structures
Loops CIS 40 – Introduction to Programming in Python
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Introduction to TouchDevelop
Module 4 Loops.
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Learning Plan 4 Looping.
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Pen Cards Pen Cards Back and Forth Draw a Line Special Effects
Matlab tutorial course
Presentation transcript:

 There are times when you will want blocks to repeat. Instead of duplicating blocks and ending up with a long script that might be confusing, there are looping control blocks that you can wrap around the script you want to repeat. › “forever” – loops until the program ends. This is basically an infinite loop as it goes on forever. › “repeat ()”- loops the specified number of times. › “repeat until < >” Repeat until the condition is True. You will use predicate blocks which can be found in the Operator Palette

 Let’s look at the “repeat until” block a bit closer. › Just like REPEAT, it will do everything inside the C- shaped block a certain number of times.  However before it starts the loop each time, it checks to see if the condition (x > 5) is true. When this is condition is true, it will not repeat again.

 Step 1 – Welcome Player, build Script!  Step 2 – Inform Player about their guess  Step 3 – Allow player to choose max value  Step 4 – Count number of guesses  Step 5 – Report number of guesses to player

 Remember from Lab1, when we created a script for the sprite to ask our name!

 Let’s look at our algorithm…

 We want to give the player more information if they don’t guess correctly.  Have the sprite tell the player if the secret number is bigger or smaller than the number that they guessed.  Work with your neighbor to add to your script…

 Remember there is more than one way to do this!

 Change your code so that the player choose the max value, instead of the sprite choosing a number between 1 and 10  Use this maximum number as the highest number that the sprite will choose.  Hint: Make a new variable for “max” value

 Make a variable for “max”

 Now let’s keep track of how many guesses it takes before the player guesses the right number.  You will need a new variable for this task and will need to add to it every time a guess occurs.

 When the player guesses the secret number tell them how many guesses it took, and congratulate them using their name.  Hint: Use previous variables!