A variable is a placeholder for a value, like x in math: var x=3;. We can assign a value to a variable and read the current value:
var x = 1; println(x); x = 3; println(x);
Click for result
println is a simple function to print on the screen the given value. You can see that the values printed are 1 and then 3.
One obvious kind of data
1+2
Click for result
Aside from numbers, a very common type of data is the String which is something between double quotes, like a name "John".
"John" + "Doe"
Click for result
var name="John"; println(name); name="Mary"; println(name);
Click for result
So, we can think of a single variable as a "block" of memory where we can store something. An array is a couple of such blocks, tied together... here's an array with 3 numbers in it: [5,2,6].
Here's an array:
var x=[1,2,3];
Click for result
var x=[1,2,3]; println(x[0]) println(x[1]) println(x[2])
Click for result
var x=[1,2,3]; x.length
Click for result
var x=[1,2,3];
for(i=0; i<x.length; i++) {
println(x[i])
}
Click for result
You need to log in to post a comment!