Sheerpower®
A Guide to the Sheerpower Language


Previous Contents Index


Chapter 4
Data Types in Sheerpower

Programs manipulate data. The data can be numeric or textual, but the data must be presented according to the rules of the Sheerpower language.

4.1 Data Types

Sheerpower accepts three basic types of data:

  1. integer numbers
  2. real numbers
  3. string (textual) data

The following sections describe each of the three types of data.

4.1.1 Integers

An integer number is a whole number with no fractional part. The following are examples of integers:


                +5%       894%       -369004% 
Integers can be positive or negative. Integer constants can end with a trailing percent sign (%). About integers:

4.1.2 Real Numbers

A real number can have a fractional part. The following are real constants:


              5.4             894.0              -369004 
Real numbers can be positive or negative. Any number that is not designated as an integer or a string is treated as a real number.

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 

4.1.3 String Data

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:

4.2 BOOLEAN

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 

4.3 Expressions

Expressions can be:

4.4 Constants

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.

4.4.1 Numeric Constants

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.

4.4.2 String Constants

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!" 

4.5 Variables

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.

4.5.1 Arrays

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