![]() |
B.1 Variables, Data Types, Database Access, Declaring Variables, and Comments |
Welcome to the fundamentals of SheerPower! In this tutorial, you'll learn how to store information in variables, understand the different types of data you can use, and how to document your code with comments. Let's get started!
Variables are containers for storing data. In SheerPower, a
variable name must begin with a letter and can contain letters,
numbers, and underscores. By convention, multi-word variable
names use underscores, like tax_rate
or
full_name$
.
Every variable holds a specific type of data. SheerPower's main data types are:
For text.
"Hello!"
For numbers.
123.45
For true/false.
true
You can create variables implicitly using suffixes, or explicitly
using the declare
statement.
$
for a STRING (e.g., name$
)?
for a BOOLEAN (e.g., is_done?
)%
for an INTEGER (a whole number -- rarely needed, use REAL)declare
): This is
clearer and helps prevent mistakes.
SheerPower's REAL
data type is special. It provides
Perfect Precision Math, which means calculations
are always exact, just like on a calculator. This prevents tiny
rounding errors that can happen in other programming languages.
(0.1 + 0.2) - 0.3
You can also create constants (variables that never change) and even your own custom data types.
You can define a default output format for a variable, which is especially useful for things like currency.
SheerPower has a secure, built-in way to access database records.
You use the syntax table_name(field_name)
. This separates
code from data, which helps prevent common security issues like SQL injection.
This is a deep topic. To learn more, see the Integrated Database Access tutorial.
Comments are notes for humans that the computer ignores. They make
your code easier to understand. Use !
or //
to write a comment.
Here is a small example that uses several of the concepts we just covered.
Hide Description
|
|
Enter or modify the code below, and then click on RUN |
Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use. |