Draft! This page is a draft - a work in progress!

TestCode1 Pub

Variable

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.

Numbers

One obvious kind of data

1+2
Click for result

  

Strings

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

  

Arrays

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

  


Was this useful?    

By: Razie | 2016-06-07 .. 2022-10-22 | Tags: admin


Viewed 274 times ( | History | Print ) this page.

You need to log in to post a comment!