Difference between revisions of "S2 Guide: Language Tutorial"
Foxfirefey (Talk | contribs) (Created page with 'S2 is a programming language designed . == Literals == Literals are basically ways of defining values inside of code. === Strings === There are two different types of strings…') |
Foxfirefey (Talk | contribs) m (→Literals) |
||
Line 3: | Line 3: | ||
== Literals == | == Literals == | ||
− | Literals are basically ways of defining values inside of code | + | Literals are basically ways of defining values inside of code -- usually when we are assigning them to variables! |
=== Strings === | === Strings === |
Revision as of 22:29, 13 June 2010
S2 is a programming language designed .
Contents
Literals
Literals are basically ways of defining values inside of code -- usually when we are assigning them to variables!
Strings
There are two different types of strings in S2.
The first kind comes in between double quotes:
var string test = "Testing";
The second kind comes in between sets of three double quotes:
"""I am also a string, but I can have "quotes" inside me."""
Some characters need to be escaped to show up properly in strings, with a backslash (\):
- If you need a newline, use: \n
- If you need a double quote inside single double quotes (or need to make three or more double quotes inside a triple double quotes), use: \"
- If you need to make a backslash, use: \\
- If you want to make a dollar sign (you'll learn why later in variables), use: \$
Integers
Integers (whole numbers) are another value like strings that the S2 language understands. This is an example of a variable being assigned a literal integer value:
var int width = 500;
True/False
You can also use true and false as values in code:
var bool isTrue = true; var bool isFalse = false;
Arrays
An array is a list of items. They must all be the same type! Here is an example with strings:
var string[] counting = ["one", "two", "three"]
Hashes
A hash is like an array, except instead of just a list of items, all of those items get to have a "key" labeling it. All keys must be strings, and all the times must be the same type. Here's an example with strings:
var string{} fruits = ["apple" => "red", "lemon" => "yellow", "grape" => "purple"]