Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.1 KB

File metadata and controls

46 lines (35 loc) · 1.1 KB

Local Variables

Mechanically, the next thing to cover is "variables".

void main() {
    String boss = "Jaqueline";
    IO.println(boss);
}

A variable declaration has three components - the "type", the "name", and the "initial value".

     String boss = "Jaqueline";
//   type   name   initial value

In this case, we are declaring a variable called "boss" and assigning it the initial value of "Jaqueline". Its "type" is "String", which I'll explain in more detail a bit ahead.

After you declare a variable and assign it a value, the "name" refers to the value on the right hand side and you can use that name instead of the value.

~void main() {
// Does the same thing as IO.println("Jaqueline");
String boss = "Jaqueline";
IO.println(boss);
~}

You may even use that name to give an initial value to another variable.

~void main() {
// Does the same thing as IO.println("Jaqueline");
String boss = "Jaqueline";
// You can use variables on the right of the = too.
String person = boss;
IO.println(person);
~}