"Sputnik" help  
Sputnik Help

Tutorials - (001) Basics


(001) Basics

Welcome to the first tutorial in the Sputnik programming language series. In this tutorial, we will cover the basics of Sputnik, including creating variables, modifying them, working with strings, arrays, and functions. Let's get started!


Creating Variables

In Sputnik, you can create variables using the my keyword followed by the variable name. Here's an example:

my $name = "John";
my $age = 25;

In the above code, we created two variables: $name and $age. The $ symbol denotes scalar variables in Sputnik.


Modifying Variables

You can modify variables by assigning new values to them. Here's an example:

$name = "Sarah";
$age = $age + 1;

In the code above, we changed the value of $name to "Sarah" and incremented the value of $age by 1.


Working with Strings

Strings in Sputnik are enclosed in double quotes. You can concatenate strings using the . operator. Here's an example:

my $greeting = "Hello";
my $name = "Alice";
my $message = $greeting . ", " . $name;

In the code above, we created a variable $message that contains the concatenated string "Hello, Alice".


Arrays

Arrays in Sputnik can hold multiple values. You can create an array using the array() function or the square brackets []. Here's an example:

my $fruits = array("Apple", "Banana", "Orange");

In the code above, we created an array called $fruits containing three elements: "Apple", "Banana", and "Orange".

You can access individual array elements using their index. Array indices start from 0. Here's an example:

my $firstFruit = $fruits[0];

In the code above, we assigned the value of the first element in $fruits ("Apple") to the variable $firstFruit.


Functions

Functions in Sputnik allow you to encapsulate reusable blocks of code. You can define a function using the Function keyword. Here's an example:

Function Greet($name)
{
    say "Hello, " . $name;
}

Greet("Alice");

In the code above, we defined a function called Greet() that takes a parameter $name and outputs a greeting. We then called the Greet() function with the argument "Alice", which printed "Hello, Alice" to the console.


Conclusion

In this tutorial, we covered the basics of Sputnik programming. We learned how to create variables, modify their values, work with strings, arrays, and functions. Building a solid foundation in these fundamental concepts will pave the way for more advanced programming in Sputnik.

In the next tutorial, we will dive deeper into Sputnik's control structures and explore conditional statements and loops.


Contact
Cheryl (uberfox@hotmail.com)
Homepage
http://ubersoft.org