1 / 17

language

language. Numbers. Numbers represent any integral or fractional number. 1, 1.5, -10 All the usual arithmetic operators are available. 1 + 2, 3 / 2.5, 10 < 20, 5 = 5 More math goodness in math math->sin(3.2). Text. A piece of text is called a String . "Hello"

merton
Download Presentation

language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. language

  2. Numbers • Numbers represent any integral or fractional number. 1, 1.5, -10 • All the usual arithmetic operators are available. 1 + 2, 3 / 2.5, 10 < 20, 5 = 5 • More math goodness in math math->sin(3.2)

  3. Text • A piece of text is called a String. "Hello" • You can glue strings together using || "Hello " || "world" • You can access the number of characters (count) and each character individually (at). "Hello"->count 5 "Hello"->at(0) H

  4. local variables • alocal variable holds a value in memory; a local variable can be read or written too. • definition var x := 0 • reading x->post to wall • update with new value x := 5

  5. while loops • while loop: repeats the same code while the condition holds • definition while ... do ... true or false happens when true

  6. for loops • for loop: repeats the same code multiple times • definition for 0 ≤ index < count do ... • index starts at 0, increments by 1 on each iteration and finishes at count-1. index goes through 0, 1, 2, … , count-1

  7. for each loops • for each loop: repeats the same code for each element of a collection • definition for each song in media->songs do... song goes through every song in songs

  8. Boolean values • a Boolean value may be trueor false • definition var b := truevar c := false

  9. if .. then .. else .. if statement: executes different code based on a Boolean condition if ... then ... else ... true or false happens when true happens when false

  10. actions functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs. action square(x : Number) returns r : Number r := x * x x is an input, it is a number the action is called ‘square’ r is an output, it is a number storing x*x into r

  11. ‘not’ operator • examples not true = false not false = true not (not true) = true

  12. ‘or’ operator • examples true or false = true false or true = true false or false = false

  13. ‘and’ operator • examples • true and false = false • false and true = false • true and true = true

  14. arithmetic operators • compares 2 numbers and returns a Boolean value • x < y = true if x is less than y; otherwise x < y = false. • x ≤y = true if x is less or equal than y; otherwise x ≤y = false.

  15. global variables • a global variable is variables available in all actions and events; a global variable can be read or written to. • global variables are stored under data. In the editor, data-> is shortened to the square symbol. • reading data->x->post to wall • update with new value data->x:= 5

  16. scope • the scope of a local variable is the area of code where this local variable exists; the scope is the outermost block of code. action go()var x := 0 for 0 ≤ index < count dovar y : = 0 scope of x scope of y

  17. while vs for • a for loop can be written as a while loop • for: • while: for 0 ≤ index < 11 do index->post to wall var index := 0 while index < 10 do index->post to wall index := index + 1

More Related