31 lines
596 B
Plaintext
31 lines
596 B
Plaintext
// 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);
|
|
|