Keywords - KidneyThief/TinScript1.0 GitHub Wiki
The syntax of TinScript closely resembles C++ in it usage of types, function definitions, namespaces, flow control, and other elements.
Starting with one of the basics, TinScript supports both single line and block comments:
- Two forward slashes '//' will allow the parser to ignore all remaining text until a new line character is reached.
- e.g. float x = 5; // the value of x will be 5
- All text between the start of a block comment /* and the block end */ is ignored.
- e.g.
/*
This entire block of text on multiple lines
is ignored by the parser.
*/
- e.g.
| Statement type | Format | Example | Comments |
|---|---|---|---|
| 'if .. else' |
if (<condition>) <consequent statement> else <alternative statement> |
// Determine if x is negative if (x < 0) Print("x is negative"); else Print("x is zero or positive"); |
|
| 'while' loop |
while (<condition>) <statement block> |
// Print 1 to 10 int counter = 1; while (counter <= 10) { Print(counter); counter = counter + 1; } |
|
| 'for' loop |
Contains three elements:
<statement block> |
// Print 1 to 10 int i; for (i= 1; i<= 10; i += 1) Print(i); |
|
| break |
Used to prematurely exit the body of any of the above statements |
// Print 1 to 7 int i; for (i = 1; i < 100; i += 1) { // should we exit? if (i == 7) break; Print(i); } |
|
| continue |
Used to prematurely exit the current iteration but does not exit the loop. |
// Print even numbers to 10 int i; for (i = 1; i <= 10; i += 1) { // skip odd numbers if ((i % 2) == 1) continue; Print(i); } |