language
description
Transcript of language
![Page 1: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/1.jpg)
language
![Page 2: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/2.jpg)
Numberso Numbers represent any integral or
fractional number.
1, 1.5, -10
o All the usual arithmetic operators are available.
1 + 2, 3 / 2.5, 10 < 20, 5 = 5o More math goodness in math
math->sin(3.2)
![Page 3: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/3.jpg)
Texto A piece of text is called a String.
"Hello"o You can glue strings together using ||
"Hello " || "world"o You can access the number of characters
(count) and each character individually (at).
"Hello"->count 5 "Hello"->at(0) H
![Page 4: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/4.jpg)
local variableso a local 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
![Page 5: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/5.jpg)
while loopso while loop: repeats the same code while
the condition holds
• definition
while ... do...
true or false
happens when true
![Page 6: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/6.jpg)
for loopso 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
![Page 7: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/7.jpg)
for each loopso 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
![Page 8: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/8.jpg)
Boolean valueso a Boolean value may be true or
false• definition
var b := true var c := false
![Page 9: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/9.jpg)
if statement: executes different code based on a Boolean condition
if ...
then ...
else ...
if .. then .. else ..
true or false
happens when true
happens when false
![Page 10: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/10.jpg)
actionsfunctions: 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
r is an output, it is a number
the action is called ‘square’
storing x*x into r
![Page 11: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/11.jpg)
‘not’ operator
o examples
not true false
false
true
not true = falsenot false = truenot (not true) = true
![Page 12: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/12.jpg)
‘or’ operator
o examples
true or false = true
false or true = true
false or false = false
or true false
true true truefalse true fals
e
![Page 13: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/13.jpg)
‘and’ operator
o examples• true and false = false
• false and true = false
• true and true = true
and true falsetrue true falsefalse
false
false
![Page 14: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/14.jpg)
arithmetic operatorso 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.
![Page 15: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/15.jpg)
global variableso 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
![Page 16: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/16.jpg)
o 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 do var y : = 0
scope
scope of x
scope of y
![Page 17: language](https://reader033.fdocuments.us/reader033/viewer/2022042718/568154ae550346895dc2b9e7/html5/thumbnails/17.jpg)
while vs foro a for loop can be written as a while loop
• for:
• while:
var index := 0while index < 10 do index->post to wall index := index + 1
for 0 ≤ index < 11 do index->post to wall