HOME - - - - - - - - - Other material for programmers - - - - - - - - - Pascalite Tutorial Table of Contents

Pascalite Programming: More on Variables

This version of this tutorial is fine tuned for a Pascalite, or the free software Pascalite emulation. Please send me an email with "complaints" if something doesn't work!

If you have the open source FPC, aka Free Pascal or Borland's Turbo Pascal (TP hereafter), then there's a separate tutorial for you, covering much of the ground as presented here for the Pascalite crowd.



In the previous tutorial, we created and used our first variables. They were of the type "byte", which means they could store numbers. (only whole numbers, and only zero - 255, but that's another story!)

Variables for numbers was a good place to start, but you can store other TYPES of data, and once you know about that, the program we wrote last time can be written more simply. Simple is always good, because it makes your code more clear... helping reveal any mistakes.

While "types of data" makes sense to anyone, for programmers, especially Pascal programmers, the word type is important. If a variable has been declared to be of, for example, "type" byte, you get a set of advantages and a set of limitations. Accepting these limitations means that it is harder to write programs with bugs, and it is easier for the person who writes the compiler to do a good job. (The compiler takes your program and converts it to what the computer needs.)


The second type of data I'm going to show you is Boolean data. A Boolean variable holds either "true" or "false".

Enter the following, or create it from the program created during the previous exercise...
program fourth;
var boItWas,boItIs: boolean;
begin
boItWas:=b1;
repeat
write(lcd,255);
if b0 then write(lcd,'b0 true'){no ; here}
   else write(lcd,'b0 false');
boItIs:=b1;
until boItIs xor boItWas;
end.


First a simple matter: The variable names. You could call them Dick and Jane. But it is better to use names that mean something. The "bo" prefix doesn't MAKE the variables Boolean... the var statement does that... but if you use such variable name prefixes, it will help you remember what the variables are being used for. I normally prefix variables of type byte with a b, so in the previous program, I would have used bItIs and bItWas as the names; I didn't only because I didn't want to burden you with the b prefix at that time.

Less simple... but important... is the subtleties in our change to the nice simple boItWas:=b1 from the complex
if b1 then ItWas:=1 else ItWas:=0;

A programming text might (quite properly) say "b1 returns a Boolean value". Is the meaning of this clear to novices in my readership? What it is saying is that when the program comes across b1, as in either of the statements quoted above, after the computer had gone off and "looked" at switch b1, in the place of b1 one is left with something drawn from the list of possible values for a Boolean type datum, i.e. "true" or "false". The reason we needed the complex version before we had Boolean variables is that a byte type variable cannot hold a Boolean value. boItWas:=b1 IS allowed, because you are trying to store either "true" or "false" in the Boolean variable boItWas. Allowed! ItWas:=b1; was NOT allowed (back when ItWas was a byte type variable) because the only values which can be held in a byte type variable are 0, 1, 2, 3.... 254, 255.

There's been another change near the end of the program. The until statement's condition is now a little less easily grasped drawing upon everyday English... but it is more elegant when you know how to read it.

Many Pascals would allow you to use the equals sign, and it would behave as it did when we were comparing what was in the byte-type variables. Pascalite, however, limits the equals sign to comparing numbers. All is not lost, though!

There are Boolean operators... in this case we are using "xor", and we've been spared the complication of the "not". First- what is an operator? Think of it as a way of binding things together. In ordinary arithmetic, we can say 3+4. The plus sign is an operator. If we perform the "add" OPERATION on three and four, the result is seven. In effect, we have "bound" the three and the four together into the more compact seven. The three and the four have been "boiled down" into a seven is another way I think of the adding operation.

The Boolean operator "xor" was named from the words "exclusive or". It is a special case of the "or" operator. When you use the ordinary "or" to combine two boolean things, the result, the boiled down, bound up, single Boolean answer is "true" if the first OR the second of the things you were ORing together were true. This includes the case where both of the inputs are true. The EXCLUSIVE "or" excludes this case. boItIs xor boItWas only boils down to something true if boItIs is true, OR if boItWas is true, but the result is false (not true) if both of them are true.

While we don't need them for this program, we might as well get the other two Boolean operators out of the way.

The Boolean operator "and" works as follows: If you "and" (yes, it is used as a verb here) two Boolean things together, the result, the answer is "true" only if the first AND the second of the things you were ANDing together were true.

And the last Boolean operator you have already met: "not". Not(boItIs) will be true when boItIs is false, and not(boItIs) will be false when boItIs is true.


This tutorial was written way back in June 2002. A derivative was cloned from it in June 2007, covering much of the same ground, but in the context of FPC, "Free Pascal". Guess what? In 5 years, my writing skills grew. If you skim through the derivative tutorial, it should cement things you mostly understand, and you will encounter material that didn't get included in the above.


Please also note that I have two other sites, and that the following search will not include them. They have their own search buttons.

My Sheepdog Guides site.
My Arunet site.

Go to the sites above, and use their search buttons if you want to search them.
To search this site....

Search this site or the web powered by FreeFind

Site search Web search
The search engine merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

You can also search this site without using forms.
Ad from page's editor: Yes.. I do enjoy compiling these things for you... hope they are helpful. However.. this doesn't pay my bills!!! If you find this stuff useful, (and you run an MS-DOS or Windows PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.


Want a site hosted, or email? You can also help me if you sign up via this link to 1&1's services. (I wouldn't recommend them unless I was happy after several years as one of their customers, but yes, they do pay me if you use this link! As do the Google advertisers, about whom I know nothing, of course.)



Valid HTML 4.01 Transitional Page tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org


Why does this page cause a script to run? Because of the Google panels, and the code for the search button. Also, I have some of my pages' traffic monitored for me by eXTReMe tracker. They offer a free tracker. If you want to try one, check out their site. Why do I mention the script? Be sure you know all you need to about spyware.
Editor's Main Homepage
How to email or write this page's editor, Tom Boyd

....... P a g e . . . E n d s .....