Programming
Cas Lemmens - Workshop 2
Regarding the feedback...
I don’t get what I’m doing...
 ➡ This is normal! It’ll get specific soon!
Programming is just not...
What did we see last time?
What did we see last time?

Variables
var welcome:String = “Hello World!”;
What did we see last time?

Variables
var welcome:String = “Hello World!”;

Mathematical functions
+ - / * %
What did we see last time?

Variables
var welcome:String = “Hello World!”;

Mathematical functions
+ - / * %

Boolean logi...
What did we see last time?

Variables
var welcome:String = “Hello World!”;

Mathematical functions
+ - / * %

Boolean logi...
Planning
 Introduction to Flash/AS3     Constructor
 Programming process           Properties
 Procedural programming     ...
Planning
 Introduction to Flash/AS3     Constructor
 Programming process           Properties
 Procedural programming     ...
Planning
 Introduction to Flash/AS3     Constructor
 Programming process           Properties
 Procedural programming     ...
Procedural programming
Loops
How can I display this?
         1x6= 6
         2 x 6 = 12
         3 x 6 = 18
         4 x 6 = 24
         5 x 6 = 30
  ...
Common loops


While-loop
For-loop
Do while-loop
while loop

 while(condition)
 {
    // Do something
 }


The loop will keep on going
 until the condition is false.
How can I display this?
         1x6= 6
         2 x 6 = 12
         3 x 6 = 18
         4 x 6 = 24
         5 x 6 = 30
  ...
while loop


while(condition)
{
   // Do something
}
while loop

var counter:Number = 1;

while(condition)
{
   // Do something
}
while loop

var counter:Number = 1;

while(counter < 11)
{
   // Do something
}
while loop

var counter:Number = 1;

while(counter <= 10)
{
   // Do something
}
while loop

var counter:Number = 1;
var table:Number = 6;
while(counter <= 10)
{
   // Do something
}
while loop

var counter:Number = 1;
var table:Number = 6;
while(counter <= 10)
{
   trace(counter + “ x “ +
   table + “ =...
while loop




    !
Infinite loop
while loop
var counter:Number = 1;
var table:Number = 6;
while(counter <= 10)
{
   trace(counter + “ x “ +
   table + “ = ...
while loop
var counter:Number = 1;
var table:Number = 6;
while(counter <= 10)
{
   trace(counter + “ x “ +
   table + “ = ...
do-while loop

do
{
     // Do something
}
while (condition);
while(condition)
{
   // Do something
}



do
{
     // Do something
}
while (condition);
for loop

for(initialize, condition, update)
{
   // Do something
}

The loop will start with the initialization, and
do t...
for loop

for(initialize,
   condition,
   update)
{
   // Do something
}
for loop
        1
for(initialize,
   condition,
   update)
{
   // Do something
}
for loop
        1
for(initialize,
   condition, 2
   update)
{
   // Do something
}
for loop
        1
for(initialize,
   condition, 2
   update)
{
   // Do something 3
}
for loop
        1
for(initialize,
   condition, 2
   update) 4
{
   // Do something 3
}
for loop
        1
for(initialize,
   condition, 2
   update) 4
{
   // Do something 3
}
What did we initialize
 before the loop?
 var counter:Number = 1;
 var table:Number = 6;
 while(counter <= 10)
 {
    trac...
What did we initialize
 before the loop?
1 var counter:Number = 1;
  var table:Number = 6;
  while(counter <= 10)
  {
    ...
for loop
        1
for(initialize,
   condition, 2
   update) 4
{
   // Do something 3
}
for loop
        1
for(var counter:Number = 1,
   condition, 2
   update) 4
{
   // Do something 3
}
What was the condition?
 1 var counter:Number = 1;
   var table:Number = 6;
   while(counter <= 10)
   {
      trace(count...
What was the condition?
 1 var counter:Number = 1;
   var table:Number = 6;
   while(counter <= 10) 2
   {
      trace(cou...
for loop
        1
for(var counter:Number = 1,
   condition, 2
   update) 4
{
   // Do something 3
}
for loop
        1
for(var counter:Number = 1,
   counter <= 10, 2
   update) 4
{
   // Do something 3
}
What did we do, and what
    did we update?
  1 var counter:Number = 1;
    var table:Number = 6;
    while(counter <= 10)...
What did we do, and what
    did we update?
  1 var counter:Number = 1;
    var table:Number = 6;
    while(counter <= 10)...
What did we do, and what
    did we update?
  1 var counter:Number = 1;
    var table:Number = 6;
    while(counter <= 10)...
for loop
        1
for(var counter:Number = 1,
   counter <= 10, 2
   update) 4
{
   // Do something 3
}
for loop
        1
for(var counter:Number = 1,
   counter <= 10, 2
   update) 4
{
   trace(counter + “ x “ + table
   + “ ...
for loop
        1
for(var counter:Number = 1,
   counter <= 10, 2
   counter = counter + 1) 4
{
   trace(counter + “ x “ ...
while-loop

var counter:Number = 1;
var table:Number = 6;
while(counter <= 10)
{
     trace(counter + “ x “ +
     table +...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
while-loop                     for-loop

var counter:Number = 1;        for(var counter:Number = 1,
var table:Number = 6; ...
Exercise 6
  for-loop
Procedural programming
Conditionals
Conditionals


 if and else
 switch
if and else
if (condition)
{
   // Do something
}
else
{
   // Do something else
}
if and else
                      if (condition)
This happens
                      {
when the
                         //...
if and else
                       if (condition)
                       {
                          // Do something
     ...
var trashCount:int = 12;

if (trashCount <= 0)
{
   trace(“Your trash is empty.”);
}
else
{
   trace(“Your trash contains”...
if (condition1)
{
   // Do something
}
else
{
   // Do something else
}
if (condition1)
{
   // Do something
}
else if (condition2)
{
   // Do something
}
else
{
   // Do something else
}
if (condition1)
This happens
                   {
when condition 1
                      // Do something
is true
         ...
if (condition1)
                      {
                         // Do something
                      }
This happens     ...
if (condition1)
                   {
                      // Do something
                   }
                   else if...
var language:String = “FR”;

if (language == “FR”)
{
     trace(“Bonjour!”);
}
else if (language == “SE”)
{
     trace(“He...
Exercise 7
  if and else
switch (condition)
{
   case condition1:
       // Do something
       break;
   case condition2:
       // Do something
 ...
switch (condition)
                    {
                       case condition1:
This happens when          // Do somethin...
switch (condition)
                       {
                          case condition1:
                              // Do...
switch (condition)
                      {
                         case condition1:
                             // Do so...
var language:String = “FR”;

switch (language)
{
     case “FR”:
          trace(“Bonjour!”);
          break;
     case “...
var language:String = “FR”;    var language:String = “FR”;

switch (language)              if (language == “FR”)
{        ...
Exercise 8
  switchin’
Procedural programming
Arrays
Array = a data-structure
        that can
        encompass
        multiple individual
        data values in an
        ...
Array = a list of things
“apple”

  “pear”

 “orange”

  “lemon”

 “banana”

“pineapple”

“strawberry”
11232

22343

 34

423

 0

 23

1224
“apple”

  “pear”

 “orange”

  “lemon”

 “banana”

“pineapple”

“strawberry”
“apple”

  “pear”       Element
 “orange”

  “lemon”

 “banana”

“pineapple”

“strawberry”
0     “apple”

1     “pear”       Element
2    “orange”

3     “lemon”

4    “banana”

5   “pineapple”

6   “strawberry”
0     “apple”

        1     “pear”       Element
        2    “orange”

Index   3     “lemon”

        4    “banana”

   ...
0     “apple”

        1     “pear”       Element
        2    “orange”

Index   3     “lemon”

        4    “banana”

   ...
0     “apple”

        1     “pear”           Element
        2    “orange”

Index   3     “lemon”

        4    “banana”
...
0     “apple”

        1     “pear”           Element
        2    “orange”

Index   3     “lemon”

        4    “banana”
...
Making an array
Making an array
Empty array:
var fruits:Array = new Array();
Making an array
Empty array:
var fruits:Array = new Array();


Array with a certain size:
var fruits:Array = new Array(3);
Making an array
Empty array:
var fruits:Array = new Array();


                                   undefined
Array with a ce...
Making an array
Empty array:
var fruits:Array = new Array();


                                     undefined
Array with a ...
Making an array
Empty array:
var fruits:Array = new Array();


                                         “apple”
Array with...
Making an array
Empty array:
var fruits:Array = new Array();


                                         “apple”
Array with...
Getting an element
Getting an element

var fruits:Array =
 new Array(“apple”,
           “pear”,
           “orange”,
           “lemon”,
   ...
Getting an element
                          “apple”

                          “pear”
var fruits:Array =
 new Array(“appl...
Getting an element
                        0   “apple”

                        1    “pear”
var fruits:Array =
 new Array(...
Getting an element
Getting an element
                 “apple”

                 “pear”

                “orange”

                 “lemon”

...
Getting an element
            0    “apple”

            1    “pear”

            2   “orange”

            3    “lemon”

...
Getting an element
                               0   “apple”

                               1    “pear”

var singleFruit...
Getting an element
                               0   “apple”

                               1    “pear”

var singleFruit...
Getting an element
                               0   “apple”

                               1    “pear”

var singleFruit...
Getting an element
            0    “apple”

            1    “pear”

            2   “orange”

            3    “lemon”

...
Getting an element
                               0   “apple”

                               1    “pear”

var singleFruit...
Getting an element
                               0   “apple”

                               1    “pear”

var singleFruit...
Changing an element
             0   “apple”

             1    “pear”

             2   “orange”

             3   “lemon...
Changing an element
                           0   “apple”

                           1    “pear”

                      ...
Changing an element
                           0   “apple”

                           1    “pear”

                      ...
Changing an element
                           0    “apple”

                           1     “pear”

                    ...
Adding an element
            0   “apple”

            1    “pear”

            2   “orange”

            3   “lemon”

   ...
Adding an element
                            0   “apple”

                            1    “pear”

                      ...
Adding an element
                            0     “apple”

                            1     “pear”

                   ...
Adding an element
            0   “apple”

            1    “pear”

            2   “orange”

            3   “lemon”

   ...
Adding an element
                       0   “apple”

                       1    “pear”

                       2   “oran...
Adding an element
                       0    “apple”

                       1    “pear”

                       2   “ora...
Adding an element
                       0    “apple”

                       1    “pear”

                       2   “ora...
Adding an element
            0   “apple”

            1    “pear”

            2   “orange”

            3   “lemon”

   ...
Adding an element
                             0   “apple”

                             1    “pear”

fruits.push(“strawbe...
Adding an element
                             0     “apple”

                             1     “pear”

fruits.push(“stra...
Adding an element
                             0     “apple”

                             1     “pear”

fruits.push(“stra...
Adding an element
            0   “apple”

            1    “pear”

            2   “orange”

            3   “lemon”

   ...
Adding an element
                                0   “apple”

                                1    “pear”
fruits.push(“st...
Adding an element
                                0     “apple”

                                1     “pear”
fruits.push(...
Adding an element
                                0     “apple”

                                1     “pear”
fruits.push(...
Adding an element
            0   “apple”

            1    “pear”

            2   “orange”

            3   “lemon”

   ...
Adding an element
                                0   “apple”

                                1    “pear”

fruits.unshift...
Adding an element
                                0   “strawberry”

                                1     “apple”

fruits....
Adding an element
                                0   “strawberry”

                                1     “apple”

fruits....
Adding an element
            0   “apple”

            1    “pear”

            2   “orange”

            3   “lemon”

   ...
Adding an element
                                0   “apple”

                                1    “pear”
fruits.unshift(...
Adding an element
                                0   “pineapple”

                                1    “apple”
fruits.uns...
Adding an element
                                0   “strawberry”

                                1   “pineapple”
fruits...
Deleting an element
             0   “apple”

             1    “pear”

             2   “orange”

             3   “lemon...
Deleting an element
             0            “apple”

             1            “pear”

             2        “orange”

 ...
Deleting an element
             0            “apple”

             1            “pear”

             2        “orange”

 ...
Deleting an element
                     0            “apple”

                     1            “pear”

                 ...
Deleting an element
                     0            “apple”

                     1            “pear”

                 ...
Deleting an element
                     0            “apple”

                     1            “pear”

                 ...
Deleting an element
                     0            “apple”

                     1            “pear”

                 ...
Deleting an element
                     0            “apple”

                     1            “pear”

                 ...
Deleting an element
                     0            “apple”

                     1            “pear”

                 ...
Deleting an element
                        0            “apple”

                        1            “pear”

           ...
Deleting an element
             0   “apple”

             1    “pear”

             2   “orange”

             3   “lemon...
Deleting an element
             0            “apple”

             1            “pear”

             2        “orange”

 ...
Deleting an element
                   0            “apple”

                   1            “pear”

fruits.pop();      2 ...
Deleting an element
                   0            “apple”

                   1            “pear”

fruits.pop();      2 ...
Deleting an element
                   0            “apple”

                   1            “pear”

fruits.pop();      2 ...
Deleting an element
                   0            “apple”

                   1            “pear”

fruits.pop();      2 ...
Deleting an element
                   0            “apple”

                   1            “pear”

fruits.pop();      2 ...
Deleting an element
                   0            “apple”

                   1            “pear”

fruits.pop();      2 ...
Deleting an element
                          0            “apple”

                          1            “pear”

fruits....
Deleting an element
             0   “apple”

             1    “pear”

             2   “orange”

             3   “lemon...
Deleting an element
             0            “apple”

             1            “pear”

             2        “orange”

 ...
Deleting an element
                   0            “apple”

                   1            “pear”

                   2 ...
Deleting an element
                   0            “apple”

                   1            “pear”

                   2 ...
Deleting an element
                   0

                   1            “pear”

                   2        “orange”
fru...
Deleting an element
                   0            “pear”

                   1        “orange”

                   2    ...
Deleting an element
                   0            “pear”

                   1        “orange”

                   2    ...
Deleting an element
                   0            “pear”

                   1        “orange”

                   2    ...
Deleting an element
                   0            “pear”

                   1        “orange”

                   2    ...
Deleting an element
                          0            “pear”

                          1        “orange”

          ...
Splice-method
splice(
 startIndex:Number,
 [deleteCount:Number],
 [value:Object]);



  split + slice = splice       Start...
Deleting with splice
Startindex 	 = 2           0   “apple”
Deletecount 	 not defined
             =
                      ...
Deleting with splice
Startindex 	 = 2           0   “apple”
Deletecount 	 not defined
             =
                      ...
Deleting with splice
Startindex 	 = 2           0   “apple”
Deletecount 	 not defined
             =
                      ...
Deleting with splice
Startindex 	 = 2           0   “apple”
Deletecount 	 not defined
             =
                      ...
Deleting with splice
Startindex 	 = 2                0   “apple”
Deletecount 	 not defined
             =
                 ...
Deleting with splice
Startindex 	 = 1          0   “apple”
Deletecount 	 3
             =
                          1    “...
Deleting with splice
Startindex 	 = 1          0   “apple”
Deletecount 	 3
             =
                          1    “...
Deleting with splice
Startindex 	 = 1          0   “apple”
Deletecount 	 3
             =
                          1    “...
Deleting with splice
Startindex 	 = 1          0   “apple”
Deletecount 	 3
             =
                          1    “...
Deleting with splice
Startindex 	 = 1          0   “apple”
Deletecount 	 3
             =
                          1
Valu...
Deleting with splice
Startindex 	 = 1          0   “apple”
Deletecount 	 3
             =
                          1   “b...
Deleting with splice
Startindex 	 = 1                0   “apple”
Deletecount 	 3
             =
                          ...
Adding with splice
Startindex 	 = 2            0   “apple”
Deletecount 	 0
             =
                            1   ...
Adding with splice
Startindex 	 = 2            0   “apple”
Deletecount 	 0
             =
                            1   ...
Adding with splice
Startindex 	 = 2            0   “apple”
Deletecount 	 0
             =
                            1   ...
Adding with splice
Startindex 	 = 2            0     “apple”
Deletecount 	 0
             =
                            1 ...
Adding with splice
Startindex 	 = 2               0     “apple”
Deletecount 	 0
             =
                           ...
Adding with splice
Startindex 	 = 2            0   “apple”
Deletecount 	 0
             =
                            1   ...
Adding with splice
Startindex 	 = 2            0   “apple”
Deletecount 	 0
             =
                            1   ...
Adding with splice
Startindex 	 = 2            0   “apple”
Deletecount 	 0
             =
                            1   ...
Adding with splice
Startindex 	 = 2            0     “apple”
Deletecount 	 0
             =
                            1 ...
Splitting with splice
Splitting with splice
var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”);
var fruits2:Array = new ...
Splitting with splice
var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”);
var fruits2:Array = new ...
Splitting with splice
var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”);
var fruits2:Array = new ...
Splitting with splice
var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”);
var fruits2:Array = new ...
Splitting with splice
var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”);
var fruits2:Array = new ...
Splitting with splice
var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”);
var fruits2:Array = new ...
Combining 2 arrays
var fruits1:Array = new 	    fruits1: 0   “apple”
	 Array(“apple”,“pear”);

var fruits2:Array = new 	  ...
Combining 2 arrays
var fruits1:Array = new 	    fruits1: 0   “apple”
	 Array(“apple”,“pear”);

var fruits2:Array = new 	  ...
Combining 2 arrays
var fruits1:Array = new 	    fruits1: 0   “apple”
	 Array(“apple”,“pear”);

var fruits2:Array = new 	  ...
Some other handy things...
var fruits:Array =
 new Array(“apple”, “pear”,
 “orange”, “lemon”, “banana”);
Some other handy things...
var fruits:Array =
 new Array(“apple”, “pear”,
 “orange”, “lemon”, “banana”);


The length of t...
Some other handy things...
var fruits:Array =
 new Array(“apple”, “pear”,
 “orange”, “lemon”, “banana”);


The length of t...
Some other handy things...
var fruits:Array =
 new Array(“apple”, “pear”,
 “orange”, “lemon”, “banana”);


The length of t...
Some other handy things...
var fruits:Array =
 new Array(“apple”, “pear”,
 “orange”, “lemon”, “banana”);


The length of t...
Array methods
Array methods
    Adding

fruits.unshift();
fruits.push();
Array methods
    Adding           Deleting

fruits.unshift();   fruits.shift();
fruits.push();      fruits.pop();
Array methods
    Adding                    Deleting

fruits.unshift();             fruits.shift();
fruits.push();        ...
Array methods
    Adding                  Deleting

fruits.unshift();           fruits.shift();
fruits.push();            ...
Exercise 9
   Arrays
No homework, but please...

Overlook it...
Experiment with it...
Ask questions!
Remember: this is only the start!
So pleas...
Q&A
Thanks!
Programming - Workshop 2
Upcoming SlideShare
Loading in...5
×

Programming - Workshop 2

510

Published on

This is the second part of my workshop on programming. We continue on loops, start with conditionals and explain arrays.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
510
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
44
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Programming - Workshop 2

  1. 1. Programming Cas Lemmens - Workshop 2
  2. 2. Regarding the feedback... I don’t get what I’m doing... ➡ This is normal! It’ll get specific soon! Programming is just not my thing... ➡ Same thing! This is very raw! I’ve already seen this! ➡ Make sure you come next time =)
  3. 3. What did we see last time?
  4. 4. What did we see last time? Variables var welcome:String = “Hello World!”;
  5. 5. What did we see last time? Variables var welcome:String = “Hello World!”; Mathematical functions + - / * %
  6. 6. What did we see last time? Variables var welcome:String = “Hello World!”; Mathematical functions + - / * % Boolean logic < > <= => == !=
  7. 7. What did we see last time? Variables var welcome:String = “Hello World!”; Mathematical functions + - / * % Boolean logic < > <= => == != Loops: while-loop
  8. 8. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Methods Methods & scopes Arrays Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  9. 9. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Methods Methods & scopes Arrays Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  10. 10. Planning Introduction to Flash/AS3 Constructor Programming process Properties Procedural programming Object Oriented programming Variables Idea Mathematical functions Inheritance Boolean Logic Datatypes & Type checking Loops Interfaces Conditionals Static classses Methods Methods & scopes Arrays Namespaces & packages Object based programming Events Classes Model - View - Controller Packages Doing a programming project Access control Flash & Flex libraries
  11. 11. Procedural programming Loops
  12. 12. How can I display this? 1x6= 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 7 x 6 = 42 8 x 6 = 48 9 x 6 = 52 10 x 6 = 60
  13. 13. Common loops While-loop For-loop Do while-loop
  14. 14. while loop while(condition) { // Do something } The loop will keep on going until the condition is false.
  15. 15. How can I display this? 1x6= 6 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 7 x 6 = 42 8 x 6 = 48 9 x 6 = 52 10 x 6 = 60
  16. 16. while loop while(condition) { // Do something }
  17. 17. while loop var counter:Number = 1; while(condition) { // Do something }
  18. 18. while loop var counter:Number = 1; while(counter < 11) { // Do something }
  19. 19. while loop var counter:Number = 1; while(counter <= 10) { // Do something }
  20. 20. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { // Do something }
  21. 21. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); }
  22. 22. while loop ! Infinite loop
  23. 23. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); }
  24. 24. while loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  25. 25. do-while loop do { // Do something } while (condition);
  26. 26. while(condition) { // Do something } do { // Do something } while (condition);
  27. 27. for loop for(initialize, condition, update) { // Do something } The loop will start with the initialization, and do the update after every loop. The loop will keep on going until the condition is false.
  28. 28. for loop for(initialize, condition, update) { // Do something }
  29. 29. for loop 1 for(initialize, condition, update) { // Do something }
  30. 30. for loop 1 for(initialize, condition, 2 update) { // Do something }
  31. 31. for loop 1 for(initialize, condition, 2 update) { // Do something 3 }
  32. 32. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  33. 33. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  34. 34. What did we initialize before the loop? var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  35. 35. What did we initialize before the loop? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  36. 36. for loop 1 for(initialize, condition, 2 update) 4 { // Do something 3 }
  37. 37. for loop 1 for(var counter:Number = 1, condition, 2 update) 4 { // Do something 3 }
  38. 38. What was the condition? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  39. 39. What was the condition? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  40. 40. for loop 1 for(var counter:Number = 1, condition, 2 update) 4 { // Do something 3 }
  41. 41. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { // Do something 3 }
  42. 42. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  43. 43. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { 3 trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  44. 44. What did we do, and what did we update? 1 var counter:Number = 1; var table:Number = 6; while(counter <= 10) 2 { 3 trace(counter + “ x “ + table + “ = “ + (counter * table)); 4 counter = counter + 1; }
  45. 45. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { // Do something 3 }
  46. 46. for loop 1 for(var counter:Number = 1, counter <= 10, 2 update) 4 { trace(counter + “ x “ + table + “ = “ + (counter * table)); 3 }
  47. 47. for loop 1 for(var counter:Number = 1, counter <= 10, 2 counter = counter + 1) 4 { trace(counter + “ x “ + table + “ = “ + (counter * table)); 3 }
  48. 48. while-loop var counter:Number = 1; var table:Number = 6; while(counter <= 10) { trace(counter + “ x “ + table + “ = “ + (counter * table)); counter = counter + 1; }
  49. 49. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } }
  50. 50. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization
  51. 51. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization
  52. 52. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization
  53. 53. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition
  54. 54. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition
  55. 55. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition
  56. 56. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition Update
  57. 57. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition Update
  58. 58. while-loop for-loop var counter:Number = 1; for(var counter:Number = 1, var table:Number = 6; counter <= 10, while(counter <= 10) counter = counter + 1) { { trace(counter + “ x “ + trace(counter + “ x “ + table + “ = “ + table + “ = “ + (counter * table)); (counter * table)); counter = counter + 1; } } Initialization Condition Update
  59. 59. Exercise 6 for-loop
  60. 60. Procedural programming Conditionals
  61. 61. Conditionals if and else switch
  62. 62. if and else if (condition) { // Do something } else { // Do something else }
  63. 63. if and else if (condition) This happens { when the // Do something condition is true } else { // Do something else }
  64. 64. if and else if (condition) { // Do something } else This happens { when the // Do something else condition is false }
  65. 65. var trashCount:int = 12; if (trashCount <= 0) { trace(“Your trash is empty.”); } else { trace(“Your trash contains” + trashCount + “ items.”); }
  66. 66. if (condition1) { // Do something } else { // Do something else }
  67. 67. if (condition1) { // Do something } else if (condition2) { // Do something } else { // Do something else }
  68. 68. if (condition1) This happens { when condition 1 // Do something is true } else if (condition2) { // Do something } else { // Do something else }
  69. 69. if (condition1) { // Do something } This happens else if (condition2) when condition 1 { is false and // Do something condition 2 is true } else { // Do something else }
  70. 70. if (condition1) { // Do something } else if (condition2) { // Do something } else This happens { when condition 1 // Do something else and 2 are false }
  71. 71. var language:String = “FR”; if (language == “FR”) { trace(“Bonjour!”); } else if (language == “SE”) { trace(“Hej!”); } else if (language == “NL”) { trace(“Hallo!”); } else { trace(“Hello!”); }
  72. 72. Exercise 7 if and else
  73. 73. switch (condition) { case condition1: // Do something break; case condition2: // Do something break; default: // Do something break; }
  74. 74. switch (condition) { case condition1: This happens when // Do something condition 1 is true break; case condition2: // Do something break; default: // Do something break; }
  75. 75. switch (condition) { case condition1: // Do something break; This happens when case condition2: condition 1 is false and // Do something condition 2 is true break; default: // Do something break; }
  76. 76. switch (condition) { case condition1: // Do something break; case condition2: // Do something break; This happens when default: condition 1 and // Do something condition 2 are false break; }
  77. 77. var language:String = “FR”; switch (language) { case “FR”: trace(“Bonjour!”); break; case “SE”: trace(“Hej!”); break; case “NL”: trace(“Hallo!”); break; default: trace(“Hello!”); break; }
  78. 78. var language:String = “FR”; var language:String = “FR”; switch (language) if (language == “FR”) { { case “FR”: trace(“Bonjour!”); trace(“Bonjour!”); } break; else if (language == “SE”) case “SE”: { trace(“Hej!”); trace(“Hej!”); break; } case “NL”: else if (language == “NL”) trace(“Hallo!”); { break; trace(“Hallo!”); default: } trace(“Hello!”); else break; { } trace(“Hello!”); }
  79. 79. Exercise 8 switchin’
  80. 80. Procedural programming Arrays
  81. 81. Array = a data-structure that can encompass multiple individual data values in an ordered list
  82. 82. Array = a list of things
  83. 83. “apple” “pear” “orange” “lemon” “banana” “pineapple” “strawberry”
  84. 84. 11232 22343 34 423 0 23 1224
  85. 85. “apple” “pear” “orange” “lemon” “banana” “pineapple” “strawberry”
  86. 86. “apple” “pear” Element “orange” “lemon” “banana” “pineapple” “strawberry”
  87. 87. 0 “apple” 1 “pear” Element 2 “orange” 3 “lemon” 4 “banana” 5 “pineapple” 6 “strawberry”
  88. 88. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” 6 “strawberry”
  89. 89. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” 6 “strawberry”
  90. 90. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” Size of array? 6 “strawberry”
  91. 91. 0 “apple” 1 “pear” Element 2 “orange” Index 3 “lemon” 4 “banana” 5 “pineapple” Size of array? 6 “strawberry” 7
  92. 92. Making an array
  93. 93. Making an array Empty array: var fruits:Array = new Array();
  94. 94. Making an array Empty array: var fruits:Array = new Array(); Array with a certain size: var fruits:Array = new Array(3);
  95. 95. Making an array Empty array: var fruits:Array = new Array(); undefined Array with a certain size: var fruits:Array = new Array(3); undefined undefined
  96. 96. Making an array Empty array: var fruits:Array = new Array(); undefined Array with a certain size: var fruits:Array = new Array(3); undefined Array with a certain elements: undefined var fruits:Array = new Array(“apple”, “pear”, “banana”);
  97. 97. Making an array Empty array: var fruits:Array = new Array(); “apple” Array with a certain size: var fruits:Array = new Array(3); “pear” Array with a certain elements: “banana” var fruits:Array = new Array(“apple”, “pear”, “banana”);
  98. 98. Making an array Empty array: var fruits:Array = new Array(); “apple” Array with a certain size: var fruits:Array = new Array(3); “pear” Array with a certain elements: “banana” var fruits:Array = new Array(“apple”, “pear”, “banana”); var fruits:Array = [“apple”, “pear”, “banana”];
  99. 99. Getting an element
  100. 100. Getting an element var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”);
  101. 101. Getting an element “apple” “pear” var fruits:Array = new Array(“apple”, “orange” “pear”, “orange”, “lemon” “lemon”, “banana”); “banana”
  102. 102. Getting an element 0 “apple” 1 “pear” var fruits:Array = new Array(“apple”, 2 “orange” “pear”, “orange”, 3 “lemon” “lemon”, “banana”); 4 “banana”
  103. 103. Getting an element
  104. 104. Getting an element “apple” “pear” “orange” “lemon” “banana”
  105. 105. Getting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  106. 106. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[4]; 3 “lemon” 4 “banana”
  107. 107. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[4]; 3 “lemon” 4 “banana”
  108. 108. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[4]; 3 “lemon” singleFruit is “banana” 4 “banana”
  109. 109. Getting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  110. 110. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[8]; 3 “lemon” 4 “banana”
  111. 111. Getting an element 0 “apple” 1 “pear” var singleFruit:String = 2 “orange” fruits[8]; 3 “lemon” singleFruit is undefined 4 “banana”
  112. 112. Changing an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  113. 113. Changing an element 0 “apple” 1 “pear” 2 “orange” fruits[2] = “raspberry”; 3 “lemon” 4 “banana”
  114. 114. Changing an element 0 “apple” 1 “pear” 2 “orange” fruits[2] = “raspberry”; 3 “lemon” 4 “banana”
  115. 115. Changing an element 0 “apple” 1 “pear” 2 “raspberry” “orange” fruits[2] = “raspberry”; 3 “lemon” 4 “banana”
  116. 116. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  117. 117. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[5] = “strawberry”; 3 “lemon” 4 “banana”
  118. 118. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[5] = “strawberry”; 3 “lemon” 4 “banana” 5 “strawberry”
  119. 119. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  120. 120. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[6] = “grape”; 3 “lemon” 4 “banana”
  121. 121. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[6] = “grape”; 3 “lemon” 4 “banana” 5 undefined
  122. 122. Adding an element 0 “apple” 1 “pear” 2 “orange” fruits[6] = “grape”; 3 “lemon” 4 “banana” 5 undefined 6 “grape”
  123. 123. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  124. 124. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”); 2 “orange” 3 “lemon” 4 “banana”
  125. 125. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”); 2 “orange” 3 “lemon” 4 “banana” 5 “strawberry”
  126. 126. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”); 2 “orange” push adds the element 3 “lemon” to the end of the array. 4 “banana” 5 “strawberry”
  127. 127. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  128. 128. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana”
  129. 129. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana” 5 “strawberry”
  130. 130. Adding an element 0 “apple” 1 “pear” fruits.push(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana” 5 “strawberry” 6 “pinapple”
  131. 131. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  132. 132. Adding an element 0 “apple” 1 “pear” fruits.unshift(“strawberry”); 2 “orange” 3 “lemon” 4 “banana”
  133. 133. Adding an element 0 “strawberry” 1 “apple” fruits.unshift(“strawberry”); 2 “pear” 3 “orange” 4 “lemon” 5 “banana”
  134. 134. Adding an element 0 “strawberry” 1 “apple” fruits.unshift(“strawberry”); 2 “pear” 3 “orange” unshift adds the element to the beginning of the array. 4 “lemon” 5 “banana”
  135. 135. Adding an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  136. 136. Adding an element 0 “apple” 1 “pear” fruits.unshift(“strawberry”, 2 “orange” “pineapple”); 3 “lemon” 4 “banana”
  137. 137. Adding an element 0 “pineapple” 1 “apple” fruits.unshift(“strawberry”, 2 “pear” “pineapple”); 3 “orange” 4 “lemon” 5 “banana”
  138. 138. Adding an element 0 “strawberry” 1 “pineapple” fruits.unshift(“strawberry”, 2 “apple” “pineapple”); 3 “pear” 4 “orange” 5 “lemon” 6 “banana”
  139. 139. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  140. 140. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before
  141. 141. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before 5
  142. 142. Deleting an element 0 “apple” 1 “pear” 2 “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before 5
  143. 143. Deleting an element 0 “apple” 1 “pear” 2 “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before 5
  144. 144. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before 5
  145. 145. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before Size after 5
  146. 146. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before Size after 5 5
  147. 147. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” 4 “banana” Size before Size after 5 = 5
  148. 148. Deleting an element 0 “apple” 1 “pear” 2 undefined “orange” delete fruits[2]; 3 “lemon” delete changes the value to undefined 4 “banana” Size before Size after 5 = 5
  149. 149. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  150. 150. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before 5
  151. 151. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” 4 “banana” Size before 5
  152. 152. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” 4 “banana” Size before 5
  153. 153. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before 5
  154. 154. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before Size after 5
  155. 155. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before Size after 5 4
  156. 156. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” 3 “lemon” Size before Size after 5 != 4
  157. 157. Deleting an element 0 “apple” 1 “pear” fruits.pop(); 2 “orange” pop removes the last 3 “lemon” element from the array Size before Size after 5 != 4
  158. 158. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana”
  159. 159. Deleting an element 0 “apple” 1 “pear” 2 “orange” 3 “lemon” 4 “banana” Size before 5
  160. 160. Deleting an element 0 “apple” 1 “pear” 2 “orange” fruits.shift(); 3 “lemon” 4 “banana” Size before 5
  161. 161. Deleting an element 0 “apple” 1 “pear” 2 “orange” fruits.shift(); 3 “lemon” 4 “banana” Size before 5
  162. 162. Deleting an element 0 1 “pear” 2 “orange” fruits.shift(); 3 “lemon” 4 “banana” Size before 5
  163. 163. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before 5
  164. 164. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before Size after 5
  165. 165. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before Size after 5 4
  166. 166. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” Size before Size after 5 != 4
  167. 167. Deleting an element 0 “pear” 1 “orange” 2 “lemon” fruits.shift(); 3 “banana” shift removes the first element from the array Size before Size after 5 != 4
  168. 168. Splice-method splice( startIndex:Number, [deleteCount:Number], [value:Object]); split + slice = splice Startindex Deleting parts of an array DeleteCount Add elements to an array Value
  169. 169. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined 2 “orange” 3 “lemon” 4 “banana”
  170. 170. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined 2 “orange” fruits.splice(2); 3 “lemon” 4 “banana”
  171. 171. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined 2 “orange” fruits.splice(2); 3 “lemon” 4 “banana”
  172. 172. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined fruits.splice(2);
  173. 173. Deleting with splice Startindex = 2 0 “apple” Deletecount not defined = 1 “pear" Value = not defined fruits.splice(2); splice with only a startindex, deletes all elements after the startindex
  174. 174. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” 3 “lemon” 4 “banana”
  175. 175. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” fruits.splice(1,3); 3 “lemon” 4 “banana”
  176. 176. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” fruits.splice(1,3); 3 “lemon” 4 “banana”
  177. 177. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “pear” Value = not defined 2 “orange” fruits.splice(1,3); 3 “lemon” 4 “banana”
  178. 178. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 Value = not defined fruits.splice(1,3); “banana”
  179. 179. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “banana” Value = not defined fruits.splice(1,3);
  180. 180. Deleting with splice Startindex = 1 0 “apple” Deletecount 3 = 1 “banana” Value = not defined fruits.splice(1,3); splice with a startindex and a deletecount, will delete a given up serie of elements
  181. 181. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” 3 “lemon” 4 “banana”
  182. 182. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” fruits.splice 3 “lemon” (2,0,”strawberry”); 4 “banana”
  183. 183. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 fruits.splice 3 “orange” (2,0,”strawberry”); 4 “lemon” 5 “banana”
  184. 184. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “strawberry” fruits.splice 3 “orange” (2,0,”strawberry”); 4 “lemon” 5 “banana”
  185. 185. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “strawberry” fruits.splice 3 “orange” (2,0,”strawberry”); 4 “lemon” splice adds elements by giving up the position with 5 “banana” startindex, and setting deletecount to 0
  186. 186. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” 3 “lemon” 4 “banana”
  187. 187. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “orange” fruits.splice (2,0,”strawberry”, 3 “lemon” “raspberry”); 4 “banana”
  188. 188. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 fruits.splice (2,0,”strawberry”, 3 “raspberry”); 4 “orange” 5 “lemon” 6 “banana”
  189. 189. Adding with splice Startindex = 2 0 “apple” Deletecount 0 = 1 “pear" Value = “strawberry” 2 “strawberry” fruits.splice (2,0,”strawberry”, 3 “raspberry” “raspberry”); 4 “orange” 5 “lemon” 6 “banana”
  190. 190. Splitting with splice
  191. 191. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array();
  192. 192. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits1: 0 “apple” 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  193. 193. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits1: 0 “apple” fruits2: 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  194. 194. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits2 = fruits1.splice(2); fruits1: 0 “apple” fruits2: 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  195. 195. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits2 = fruits1.splice(2); fruits1: 0 “apple” fruits2: 1 “pear" 2 “orange” 3 “lemon” 4 “banana”
  196. 196. Splitting with splice var fruits1:Array = new Array(“apple”,“pear”, “orange”, “lemon”, “banana”); var fruits2:Array = new Array(); fruits2 = fruits1.splice(2); fruits1: 0 “apple” fruits2: 0 “orange” 1 “pear" 1 “lemon” 2 “banana”
  197. 197. Combining 2 arrays var fruits1:Array = new fruits1: 0 “apple” Array(“apple”,“pear”); var fruits2:Array = new 1 “pear" Array(“orange”, “lemon”, “banana”); fruits2: 0 “orange” 1 “lemon” 2 “banana”
  198. 198. Combining 2 arrays var fruits1:Array = new fruits1: 0 “apple” Array(“apple”,“pear”); var fruits2:Array = new 1 “pear" Array(“orange”, “lemon”, “banana”); fruits1.concat(fruits2); fruits2: 0 “orange” 1 “lemon” 2 “banana”
  199. 199. Combining 2 arrays var fruits1:Array = new fruits1: 0 “apple” Array(“apple”,“pear”); var fruits2:Array = new 1 “pear" Array(“orange”, “lemon”, “banana”); 2 “orange” fruits1.concat(fruits2); 3 “lemon” fruits2: 4 “banana”
  200. 200. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”);
  201. 201. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length;
  202. 202. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length; return 6
  203. 203. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length; return 6 Printing out the array: fruits.toString();
  204. 204. Some other handy things... var fruits:Array = new Array(“apple”, “pear”, “orange”, “lemon”, “banana”); The length of the array: fruits.length; return 6 Printing out the array: fruits.toString(); return apple,pear,orange,orange,lemon, banana,pineapple,strawberry
  205. 205. Array methods
  206. 206. Array methods Adding fruits.unshift(); fruits.push();
  207. 207. Array methods Adding Deleting fruits.unshift(); fruits.shift(); fruits.push(); fruits.pop();
  208. 208. Array methods Adding Deleting fruits.unshift(); fruits.shift(); fruits.push(); fruits.pop(); Splice fruits.splice(2); fruits.splice(2,2); fruits.splice(2,0,”apple”);
  209. 209. Array methods Adding Deleting fruits.unshift(); fruits.shift(); fruits.push(); fruits.pop(); Splice Other fruits.splice(2); fruits.length; fruits.splice(2,2); fruits1.concat(fruits2); fruits.splice(2,0,”apple”); fruits.toString();
  210. 210. Exercise 9 Arrays
  211. 211. No homework, but please... Overlook it... Experiment with it... Ask questions! Remember: this is only the start! So please, get this!
  212. 212. Q&A
  213. 213. Thanks!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×