For Loops & Arrays. my_rect_pink_mc.width = 40 my_rect_pink_mc.alpha =.5 trace my_rect_pink_mc.x= 20 my_rect_pink_mc.y= 20 for (var i:int = 0; i < 250;

Slides:



Advertisements
Similar presentations
1 Pertemuan 14 PHP: Conditions-loops-functions-Array Last Updated: 23 rd May 2011 By M. Arief
Advertisements

String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
A loop is a repetition control structure. it causes a single statement or block to be executed repeatedly What is a loop?
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Loops – While, Do, For Repetition Statements Introduction to Arrays
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2010SCM-CityU1.
JavaScript Switch Statement. Switch JavaScript Switch Statement If you have a lot of conditions, you can use a switch statement instead of an if…elseif…
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Arrays and Control Structures CST 200 – JavaScript 2 –
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
Loops Doing the same thing over and over and over and over and over and over…
For Loops. Challenge: Racer ● Simulate a race that says “Now on lap X” for 10 laps. ● Make X vary, so it says 1, then 2, then 3 ● Use only one output.
Arrays – What is it? – Creation – Changing the contents Functions – What is it? – Syntax – How they work – Anonymous functions A quick lesson in Objects.
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.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Java Arrays …………. Java Arrays …………. * arrays are objects in Java * arrays are objects in Java * an array variable is a reference * an array variable is.
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
SM1205 Interactivity Topic 06: Iteration and Multiple Objects Spring 2012SCM-CityU1.
CRE Programming Club - Class 4 Robert Eckstein and Robert Heard.
Built-in Data Structures in Python An Introduction.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Functions & Objects Flash ActionScript 3.0 Introduction to Thomas Lövgren, Flash developer
Chapter 4 Grouping Objects. Flexible Sized Collections  When writing a program, we often need to be able to group objects into collections  It is typical.
1 BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA AND DEFINITE LOOPS.
Course A201: Introduction to Programming 09/16/2010.
1 The for loop. 2 Repetition with for loops So far, repeating a statement is redundant: System.out.println("Homer says:"); System.out.println("I am so.
ADMIT TICKET WHAT DOES THIS OUTPUT? double y = 2.5; int x = 6 / (int) y; System.out.println(“x = “ + x);
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.
C Programming – Part 3 Arrays and Strings.  Collection of variables of the same type  Individual array elements are identified by an integer index 
Introduction to Strings Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
ActionScript: For Loops, While Loops, Concatenation and Arrays MMP 220 Multimedia Programming This material was prepared for students in MMP220 Multimedia.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
IS2802 Introduction to Multimedia Applications for Business Lecture 4: JavaScript, Loops, and Conditional Statements Rob Gleasure
Arrays-. An array is a way to hold more than one value at a time. It's like a list of items.
Language Find the latest version of this document at
CSD 340 (Blum)1 Arrays See Beginning JavaScript pp
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
Introduction to Computing Using Python Repetition: the for loop  Execution control structures  for loop – iterating over a sequence  range() function.
JavaScript, Sixth Edition
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 3: Built-in functions.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 9: Arrays; Revision Session.
Computer Program Flow Control structures determine the order of instruction execution: 1. sequential, where instructions are executed in order 2. conditional,
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Magic 8 ball. "Design and write a python program that emulates a Magic Eight Ball. Your program should continually prompt the user to enter a question.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
String and Lists Dr. José M. Reyes Álamo.
Trace Tables In today’s lesson we will look at:
Array in C# Array in C# RIHS Arshad Khan
Chapter 9 Repetition.
Topic: Iterative Statements – Part 1 -> for loop
REPETITION CONTROL STRUCTURE
JavaScript Create Array object
Repetition: the for loop
Chapter 5 Repetition.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
String and Lists Dr. José M. Reyes Álamo.
Programming Control Structures with JavaScript Part 2
Loops and Arrays in JavaScript
Repetition: the for loop
Conditional Loops Counted Loops
Topic: Iterative Statements – Part 2 -> for loop
Class code for pythonroom.com cchsp2cs
Lecture 9: JavaScript Syntax
Tuple.
Presentation transcript:

For Loops & Arrays

my_rect_pink_mc.width = 40 my_rect_pink_mc.alpha =.5 trace my_rect_pink_mc.x= 20 my_rect_pink_mc.y= 20 for (var i:int = 0; i < 250; i++) { trace (i + ' this is the current loop')}function moveMe(evt:Event):void {//trace ('i am moving....'); star_fish.rotation += 10 if ( star_fish.hitTestObject(myFishy_mc )) {trace ('I was it')}stage.addEventListener(MouseEvent.MOUSE_MOVE, followMouse); 20 for (var i:int = 0; i < 250; i++) trace If(event.keyCode == 7){myFishy_mc.x -= 5;} function moveFish(thisFish:MovieClip,targetLocH:Number):void import flash.events.KeyboardEvent;import flash.events.MouseEvent; import flash.ui.Keyboard; package {import flash.display.Sprite;public class FishClass extends Sprite{public function FishClass()20 for (var i:int = 0; i < 250; i++) { trace (i + ' this is the current loop' ){ this.addEventListner (MouseEvent.ROLL_OUT, scaleMeDown)} private function scaleMeUp (event:MouseEvent):void if (star_fish.hitTestObject(myFishy_mc)){trace ('I was it') }}{this.scaleX = 1.5;this.scaleY = 1.5;}private function scaleMeDown ( event:MouseEvent):void{this.scaleX = 1; my_rect_pink_mc.width = 40 my_rect_pink_mc.alpha =.5 my_rect_pink_mc.x= 20 this.scaleY = 1;}}} addEventListner

to perform repetitive tasks, we use a loop a loop is type of statement that causes a block of code to be repeated

Repeat Loops How to read this? var i:int; for (i = 0; i < 5; i++) { trace( i); } the statements to repeat are listed between the brackets: { } the keyword for starts the loop the comparison (i < 5) indicates when to quit repeating the loop the loop stops repeating when x is equal to 5 no longer less than 5 to make the loop count to 500, simply change 5 to 500

Repeat Loops How to read this? for (i = 0; i < 5; i++) { trace( i); } for (initialize; compare; update) { Statements }

Repeat Loops How to read this? for (i = 0; i < 5; i++) { trace( i); } Initialize Variable staring a 0 Action to carry out CompareUpdate…….

Arrays What is an Array? an array is a list of data values Means not having to make lots and lots of variables fruit1 = "oranges"; // A single string value fruit2 = "apples"; // Another string value this code creates an array to store both values: var fruitList = ["oranges", "apples"];

Arrays What is an Array? this code creates an array to store both values: var fruitList = ["oranges", "apples"]; array constructor: new Array("item1", "item2") in ActionScript, arrays can contain any kind of data shoppingList = ["oranges", 5, "apples", 2];

Arrays shoppingList = ["oranges", 5, "apples", 2]; each item stored in an array is called an element each element's position in the array is its index indices start at 0 for example, here are the indices for shoppingList: 0: "oranges" 1: 5 2: "apples" 3: 2 the number of elements in an array is called its length for example, the shoppingList's length is 4

Arrays to set an element's value, use this syntax: theArray[theElementIndex] = theValue; for example: // Make an array var cities = ["Toronto", "Montreal", "Vancouver", "Tokyo"]; // cities is now: ["Toronto", "Montreal", "Vancouver", "Tokyo"] // Set the value of the array's first element // cities becomes ["London", "Montreal", "Vancouver", "Tokyo"] cities[0] = "London";

Arrays & For Loops var myArray:Array = new Array("a", "b", "c"); var i:int; for (i = 0; i < (myArray.length); i++) { trace(myArray[i]); } Will print into the output window a b c

CODE 101- SYNTAX Live Demo