feat: add examples with descriptions
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
// There are two ways to work with variables
|
||||
// 1. Declare variable:
|
||||
str someString = "world, hello!";
|
||||
|
||||
// 2. Change variable value:
|
||||
someString = "hello, world!";
|
||||
|
||||
// Variables helps you store values to use it later
|
||||
int a = 2;
|
||||
int b = a + a * a;
|
||||
int c = a * b;
|
||||
|
||||
printline("Now we got 12:");
|
||||
printline(c);
|
||||
|
||||
// Also, there is many different types to help your program
|
||||
// work with many things:
|
||||
int signedInteger;
|
||||
uint unsignedInteger
|
||||
str string;
|
||||
bool boolean;
|
||||
|
||||
i8 integer1; // 8-byte int
|
||||
i16 integer2; // 16-byte int
|
||||
i32 integer3; // 32-byte int
|
||||
i64 integer4; // 64-byte int
|
||||
|
||||
u8 integer5; // unsigned 8-byte integer
|
||||
u16 integer6; // unsigned 16-byte integer
|
||||
u32 integer7; // unsigned 32-byte integer
|
||||
u64 integer8; // unsigned 64-byte integer
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// When you need to check some value
|
||||
// a conditional statements might help you
|
||||
|
||||
int valueToCheck = 2 + 2;
|
||||
if (valueToCheck == 4)
|
||||
{
|
||||
printline("Yay! 2 + 2 = 4");
|
||||
}
|
||||
|
||||
// Conditional statement uses condition in pairs
|
||||
// after `if` keyword and executes command(s) after
|
||||
// if condition turns out to be true
|
||||
|
||||
// Otherwise, to execute block when condition turns
|
||||
// out to be false, you can use `else` keyword:
|
||||
|
||||
int age = 30;
|
||||
|
||||
if (age <= 20)
|
||||
printline("You're too young");
|
||||
else
|
||||
{
|
||||
age = 20;
|
||||
printline("You looks too young!");
|
||||
}
|
||||
|
||||
// NOTE: If you need to execute only one statement
|
||||
// inside `if` or `else` block, then the curly
|
||||
// braces can be omitted.
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// If you have some code section which is
|
||||
// duplicated in program several times
|
||||
// then it means your program needs some
|
||||
// functions!
|
||||
|
||||
fn doSomeWork()
|
||||
{
|
||||
printline("Some work");
|
||||
}
|
||||
|
||||
// If the function makes some kind of
|
||||
// calculations then you should specify
|
||||
// the result type
|
||||
|
||||
fn sum(int a, int b) int
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
// The `return` keyword can be used to
|
||||
// actually return the value from the
|
||||
// function. Also, you can specify list
|
||||
// of arguments that you will use inside
|
||||
// the function
|
||||
|
||||
int first = 5;
|
||||
int second = 6;
|
||||
int result = sum(first, second);
|
||||
printline(result);
|
||||
|
||||
Reference in New Issue
Block a user