Table of Contents
The General Definiton Of Boolean
What is boolean in Pascal? Booleans are the data types of code which represent the values true or false. This data type is also known for its use in logical operators of circuits. That’s more or less related to engineering. But some people among our community might have heard of the Logical Gates. That’s advanced stuff but if you already know what they are, Boy you and i are gonna get along well!
Usage Of Booleans
Booleans hold the values of True and False as written above. As such we can use them in a variety of circuits and complex codes to make life generally a whole lot easier. A example will soon follow but first we have a few key to define about this data type. Considering the fact its powerful it’s got it’s importance like all other data types.
Limits
1 – It can only hold True and False. No more, No less. Booleans will give errors when given values of numbers, letters or symbols. Anything other than true and false is wrong within the Boolean data type and wil result in errors.
2 – A Boolean is very hard to use on its own. Rather we can use it to add more power to the existing Strings, Integers and Characters. I’ll explain that below with a example real quick, For now keep these 2 points in mind.
Examples To Use Booleans
The following example is what you can use to see the Boolean data type in action. Note that in this example you may or may not understand some part of the code. Worry not as i mentioned in previous posts. I will explain the parts of the code that you don’t understand in a later post. For now Copy and Paste!
Step 1 – Creating A New Program
For this example we use the free Lazarus IDE. Open up Lazarus and create a new program as shown in the Image Below.
Step 2 – Choosing A Program
When clicking the New button, Lazarus will give you a whole lot of software options to choose from and make. As is in previous examples we will use the command line Program to keep things simple and elegant. Select Program from the menu that pops up as shown in the Image below.
Step 3 – The Code Itself
After choosing Program and clicking OK the IDE will make a brand new place for you to write the code. Copy and paste what i did as shown in the section below, and once done i’ll explain a bit of the code.
var numbers : integer; var truth : Boolean; begin numbers := 2; if numbers = 1 then begin truth := true; writeln('The Program we made told us that if the variable Numbers is equal to 1 then tell us that if its true.'); end else writeln('The Program Says That the fact that numbers is equal to 1 is false.'); writeln; writeln; writeln('Press <Enter> To Quit The Program'); readln; end.
Slight Explanation On Code
The code i used above is simple. I can explain what it did with a simple sentence. I’ll write it in a normal english sentence as written in the below paragraph.
“Hey Computer i’m declaring 2 variables truth and numbers. Truth is a boolean data type and Numbers is a integer data type. Now give Numbers a value of 1. Now if Numbers is 1 then i want you to declare the boolean data type as True and Print on the screen the message i told you.”
That’s that in a nutshell. It’s fine if you do not understand the code i wrote in the above paragraphs. (Although if you did understand what i wrote, Congrats!). I’ll be sure to answer any questions you may have not only in the comments but also in future posts. For now we move on!
Another Way To Learn
To further improve our understanding on Booleans. I recommend watching a video from Youtube. Posted by a well known content creator named SchoolFreeWare. Use this for further understanding the concepts of Pascal!
Be sure to leave a comment if i left out some minor (or greater!) detail. I’ll be sure to fix it as soon as possible. Not gonna lie it’s fun to have you all to journey with! I hope you feel the same. Moving On!