Previous | Contents | Index |
Programs manipulate data. The data can be numeric or textual, but the data must be presented according to the rules of the Sheerpower language.
Sheerpower accepts three basic types of data:
The following sections describe each of the three types of data.
An integer number is a whole number with no fractional part. The following are examples of integers:
+5% 894% -369004% |
A real number can have a fractional part. The following are real constants:
5.4 894.0 -369004 |
A real number without a decimal point is called an ambiguous constant. About real numbers:
Here is an example of Sheerpower exact math:
Example 4-1 Sheerpower Exact Math |
---|
x = 0 for i = 1 to 10000 x = x + .01 next i if x = 100.00 then print 'It is right.' It is right. |
If you try this example in another programming language (Visual Basic or C++ for example), you will not get the correct answer. Here is another example:
Example 4-2 Sheerpower Exact Math |
---|
print 123456789.012345 * 87654321.123456789 10821521028958940.344459595060205 |
String data consists of text. Text can consist of any characters. All of the following are valid string constants:
Example 4-3 String data |
---|
'Hello, Fred.' 'Account number (##-####)' '65' |
About string data:
Boolean variables represent either a TRUE or FALSE condition. These variables can be expressed with a trailing "?". For example:
Example 4-4 BOOLEAN Variables |
---|
done? = FALSE do input 'Ready': ans$ if _exit then done? = true if _back then done? = true loop until done? end Ready? exit |
Expressions can be:
A constant is a value that does not change during a program execution. Constants can be any of the three data types: integer numeric, real numeric or string.
Integer numeric constants are written with digits, with no decimal fraction. An integer constant can end with a percent sign. Examples:
235 412% |
Real numeric constants are written with a sign, digits, and a decimal point. For example, 5.38 is a real numeric constant.
String constants must be enclosed in quotes. The quotes are called string delimiters. They tell Sheerpower where the string begins and ends. The quotes are not considered part of the string. Everything within the quotes is considered part of the string. Note that the following strings are different:
Example 4-5 String Constants and Delimiters |
---|
print 'Account number (##-####)' print ' Account number (##-####)' end Account number (##-####) Account number (##-####) |
An empty string is called a null string. A null string is indicated by a pair of quotes with nothing between them ("").
String delimiters can be single quotes (') or double quotes ("). However, the quotes must match and be paired.
Quotes can be included as part of a string by using them within the string delimiters. For example:
"Message'Time to go home!'" |
The string part of this is:
Message 'Time to go home!' |
The delimiter quotes can be used within a string by repeating them twice. For instance:
"Message ""Time to go home!""" |
The string part of this is:
Message "Time to go home!" |
Variables are a way of storing values that can change in the program during execution. A variable names a storage location. The value of the variable is stored in this location. Here are two types of variables:
Two other constructs are used in ways similar to variables---you can use them in expressions and assign values to them:
Variables are represented by a name consisting of a letter or series of letters, numbers and underscore characters. Variables:
Some examples of valid variables are:
TODAY$ X% Z INDEX |
The following are examples of string variables:
TODAY$ X$ LAST_NAME$ ANSWER$ |
The following are examples of real numeric variables:
INDEX Z COUNTER AMOUNT |
Sheerpower uses the last assigned value when a variable is referenced. See Section 5.7, Private Variables in Routines for more information on using variables.
An array is a variable that consists of a group of elements. Each element represents a storage location. A different value can be assigned to each element. Here is an example of an array:
QUANTITY(1) QUANTITY(2) QUANTITY(3) QUANTITY(4) QUANTITY(5) |
To indicate which element to access, use numbers after the array name, called subscripts. The subscripts are enclosed in parentheses. Example: amount(3,2)
Subscripts must be given as integers. If a real numeric subscript is given, it will be rounded and the integer portion used. Arrays can contain real numeric, integer or string values. String and integer arrays are designated by placing the appropriate symbols after the array name and before the subscript. For example:
a$(5,10) a%(5,10) |
About arrays:
Previous | Next | Contents | Index |