Editing Squirrel Variables

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
<div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align: center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/An_Introduction_to_Squirrel BACK]</div><div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/An_Introduction_to_Squirrel HOME]</div><div style="width:33.333%; z-index: 1; top: 0px; position: sticky; height: 30px; display: inline-block; text-align:center; line-height: 30px; background-color:#BBBBBB;">[https://sigwiki.potato.tf/index.php/Squirrel_Comments NEXT]</div>
Every program in any programming language is comprised of a set of instructions called '''statements''' which manipulate data to produce a desired result. Programs store data into regions of memory as '''objects'''. Objects which we give an '''identifier''' (name) in our programs are called '''variables'''. You can think of statements as analogous to sentences in the language we speak to each other, each requires a specific set of items to be considered valid, and each is ended with a specific character. Sentences are mostly ended with periods, and statements always end with a semicolon.
 
Every program in any programming language is made up of instructions called '''statements''' which manipulate data to produce a desired result. Squirrel stores data into regions of memory as '''objects'''. Objects which we give an '''identifier''' (name) in our programs are called '''variables'''.
 
You can think of statements as analogous to sentences in the language we speak to each other; each requires a specific set of items in a certain order to be considered valid, and each is ended with a specific character. Sentences are mostly ended with periods, whereas statements always end with a semicolon.




Line 25: Line 21:




In addition, identifiers cannot be the same name as a '''keyword''', which are special identifiers reserved by the language for its use in the syntax. We'll go over most of these throughout the guide, so don't worry about memorizing them just yet.
In addition, identifiers cannot be the same name as a keyword, which are special identifiers reserved by the language for its use in the syntax. We'll go over most of these throughout the guide, so don't worry about memorizing them just yet.
{| class="wikitable" style="width:75%; margin:auto; text-align:center font-weight:bold; font-size:125%"
{| class="wikitable" style="width:75%; margin:auto; text-align:center font-weight:bold; font-size:125%"
|+Keywords
|+Keywords
Line 91: Line 87:
local y = 10;
local y = 10;


printl(y);
x = 5;
 
x = 0;
y = 0;
y = 0;
</syntaxhighlight>
</syntaxhighlight>


Here we define x and initialize y to 10, print y to console, and then set them both to 0 afterwards.
Here we define x and initialize y to 10, and then set x to 5 and y to 0 afterwards.
 
 
Normal variables like the ones we defined above can be changed at any time, however what if we have a variable that we don't want to change or that wouldn't make any sense to change? This is where constants come in.
 
<syntaxhighlight lang="c" line="1" start="1" style="font-weight:bold;>
const DAYS_IN_WEEK = 7;
const PI = 3.1415926535;
const NAME = "Dell Conagher";
</syntaxhighlight>
 
Constants are variables which cannot be changed after they are created, however they can only contain certain values. Constants may only be created with integer, float, or string '''literals'''. We go over what these are in depth in the [https://sigwiki.potato.tf/index.php/Squirrel_Data_Types Data Types] chapter. For now if you'd like a reference of what those are, the variables in the above example contain the specified types. <code>7</code> is an '''integer''', <code>3.14</code> is a '''float''', and <code>"Dell Conagher"</code> is a '''string'''.
Please note that all contributions to SigMod are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see SigMod:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)