Control Structures http://www.alice.org/resources/lessons/control-structures-overview/

Slides:



Advertisements
Similar presentations
GAME:IT Junior Learning Game Maker: The Control Tab.
Advertisements

Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Basic Building Blocks of Programming. Variables and Assignment Think of a variable as an empty container Assignment symbol (=) means putting a value into.
Bug Session Two. Session description In this session the use of algorithms is reinforced to help pupils plan out what they will need to program on their.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
An Introduction to Textual Programming
Programming & Scratch. Programming Learning to program is ultimately about learning to think logically and to approach problems methodically. The building.
COMPUTER PROGRAMMING. Control Structures A program is usually not limited to a linear sequence of instructions. During its process it may repeat code.
COMPUTER PROGRAMMING. Iteration structures (loops) There may be a situation when you need to execute a block of code several number of times. In general,
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 ‏ Control Structures.
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Mathematical Expressions, Conditional Statements, Control Structures
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Chapter 7: Repetition Structure (Loop) Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Computer Programming Skills.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Scratch Programming Cards
String and Lists Dr. José M. Reyes Álamo.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Creating a UFO Rescue Game in Alice
Broadcasting (Adding a new level)
Chapter 6: Loops.
Programming & Scratch.
Teaching Characters to Walk: Learning Methods, Part 1
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Programming: Simple Control Structures
Repetition Structures Chapter 9
Chapter 3: Decisions and Loops
Putting Objects in Motion
Programming: Simple Control Structures
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.
Simple Control Structures
Counted Loops.
Let's Race! Typing on the Home Row
The structure of computer programs
Introduction to Events
Creating a UFO Rescue Game in Alice
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Lecture 4A Repetition Richard Gesick.
LESSON 11 – WHILE LOOPS UNIT 5 – 1/10/17.
Learn… Create… Program
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Making Procedural Methods
CS190/295 Programming in Python for Life Sciences: Lecture 6
HAPPY NEW YEAR! Lesson 7: If-statements unplugged
Iteration: Beyond the Basic PERFORM
Learn… Create… Program
More programming with "Processing"
Arrays
String and Lists Dr. José M. Reyes Álamo.
Using Functions
Programming: Simple Control Structures
Algorithm and Ambiguity
ICT Gaming Lesson 3.
Scratch Summer Session 2
Tutorial for Arrays and Lists
Topics Introduction to Repetition Structures
Learn… Create… Program
Learn… Create… Program
The structure of programming
Python While Loops.
CSC1401 Manipulating Pictures 2
Thinking procedurally
under the direction of Professor Susan Rodger
LOOP Basics.
Presentation transcript:

Control Structures http://www.alice.org/resources/lessons/control-structures-overview/

Control Structures What is a Control Structure? A control structure is a programming element that controls which statements in a program are executed and in what order. Types of control structures in Alice are: Sequential: Do in Order Concurrent: Do Together and Each In_Together Conditional: If_ Repetition: Count_ For Each In_ and While_

Control Structures Control Panel The control panel is where you find the control structure elements that you can use in your Alice programs.

Control Structures Code Blocks When you drag a control structure into your program they create code blocks that have empty areas that allow you to add statements into the block. Each type of code block will have different required fields and formats based on how they will function.

Control Structures Do In Order The most basic control structure in Alice is a do in order block. A do in order block will tell the program to execute the enclosed statements in sequence (one after another). All methods in Alice start with a do in order control structure as the default behavior.

Control Structures Do Together A do together code block can be used to execute all of the statements in the block at the same time. Do together is very helpful for things like: complex movement such having a fish move forward while having it’s tail swish at the same time. having multiple characters animating at the same time.

Control Structures Each In Together An each in_ together block in Alice is a do together control structure that includes the use of an array. It will execute the statements in the block at the same time for all of the elements in the array. An each in_together can be used to have a whole group of characters perform the same action simultaneously such as having a row of characters dancing at the same time.

Control Structures If Else Many times in a program you want something to execute only under certain circumstances. In many programs this is expressed using an If_ else statement. This means that when this part of the program is being executed if_ a certain condition is true or false such as “the timer has run out” do this set of directions otherwise (else) do this other set of directions such as “keep playing”. This structure is often paired with other patterns that allow it to be checked multiple times or after an event has changed conditions in the world.

Control Structures Conditional Constructions In Alice you will use conditionals in conjunction with event listeners for things like if a key is pressed or if the mouse is clicked. You may also use a conditional with a loop to continuously check to see if a score has been reached or a timer has run out In order to use conditionals you may need to use functions, variables, and/or events

Control Structures Looping Computers don’t get bored or tired and are happy to do the same thing over and over again. Lots of time you may want the same action to be repeated a number of times. There are 3 ways in Alice you can achieve this. A count loop defines how many times you want the program to execute the contained code. A for each in loop defines how many times and how you want the program to execute the contained code based on elements in an array. A while loop tells the program to continue to do the contained code until the defined condition is no longer accurate.

Control Structures Count Loop A count_ block in Alice will execute a method the number of times that you define. This is a great way to have your animation run the same animation multiple times without having to write the same code lots of times such as having a character do jumping jacks. The computer is not even breaking a sweat after 10.

Control Structures For each In Loop A for each in_ block in Alice will execute the statements inside the block repeatedly for each element in an array. Additionally you can substitute the element from the array in each time the statements are executed to easily create complex animations. Using an array of characters you can repeat the same statements multiple times replacing it each time with a different character from the array to have a row of characters raise their arms in order and do the wave.

Control Structures While Loop A while_ code block can be used to have your program execute the same instructions for an undefined amount of times based on conditions in the program. A while_ can be used to make an animation repeat for the duration of your program using a “while program is active” condition such as having clouds move across the sky. A while_ can be used to have an animation play only when a character is close enough to an object or looking at it such as having a dog jump up and down when the character is close to it.

Control Structures Nested Code Blocks You can put control structures inside of other control structures. This will come in very handy when trying to synchronize when events happen. In Alice you will often want to have multiple do in orders nested inside a do together to enable multiple different characters to simultaneously do a string of different actions.

Tips and Tricks

Tips and Tricks Achieving Different Movements Diagonal move Do together Move forward 1 meter Move left 1 meter Move on a slope Do together Move forward 1 meter Move up1 meter Move on an arc Do together Move forward 2 meter Turn right .5 rotations

Tips and Tricks Synchronization Remember that each Alice statement defaults to a duration of 1 second When using a do together you will need to change a single statement duration detail to 3 seconds if you want it to take the same amount of time of another animation that is comprised of 3 separate statements.

Tips and Tricks Dissolving and Converting Right clicking on a control structure will allow you to: dissolve constructed control structures change a do together into a do in order or vice versa