Getting Started
Introduction
Sample Programs
QBasic IDEs
History
Advice
Tools
Mini-Tutorial
Tutorial
Code Snippets

Resources
Web Sites
More Tutorials
Vendors
Books
Magazines
NewsLetters
NewsGroups
Forums
User Groups
Talk Shows
Blogs

GBIC >> QBasic >> Tutorial >> Operators

QBasic Information Center Tutorials - Operators
These tutorials were written to help you get a quick, but thorough, understanding of QBasic - the scope of the language as well as it's specific capabilities.

Operators
QBasic contains a standard set of operators, as shown in the following list.

     +        and       <  
     -        or        >  
     *        xor       <= 
     /        not       >= 
     ^        imp       <>
     MOD      eqv    

The rest of this page breaks these into common groups for discussion.

Basic Arithmetic
The = + - * / ^ MOD operators perform as expected.

    =     x$=2          # assigns $x the value of 2
    +     x$ = x$ + 1   # add
    -     x$ = x$ - 1   # subtract
    *     x$ = x$ * 2   # multiply
    /     x$ = x$ / 2   # divide
    ^     x$ = 2 ^ 6    # exponentiation
    MOD   x$ MOD 5      # modulus (whole number remainder of division)

String Operators
QBasic uses the + operator to combine strings.

     +      string concatenation     # "a" + "b" yields "ab"

Logical Operators
Logical operators test to see if expressions or values are true or false. In QBasic the values 0 is false. All non-zeros are true.

Here are the logical operators supported by QBasic.

     and
     or 
     xor
     not
     imp
     eqv

Relational/Equality Operators
In QBasic, string and number comparison operators are same. The operators are shown below.

    Number    Comparison
      =         equal
      !=        not equal
      <         less than
      >         greater than
      <=        less than or equal to
      >=        greater than or equal to
      <>        trinary comparisons

If you have suggestions or corrections, please let me know.