This article will be a continued section from what we started in the last article, which is about basic programming terminologies. In this article, we will pick up the terminologies we haven't seen in the previous article, which will help us understand Pseudocode and Flowchart easily and develop one for our program.

The terminologies we have seen in the previous article were: Variables, Constants, Datatypes, Declaration, Array, and, Expressions and statements. You can use this link if you need a quick refresher before you start reading this article. In this article, we will briefly talk about Conditions, Code blocks, Loops, and Functions.

Let's get started:

Conditions

In the previous article, we talked about both boolean data types and expressions. By now, you already know what boolean data types represent; they represent either true or false values, right? We also defined expressions as incomplete statements those yield values. Thus, conditions are expressions those yields only boolean values.

Most of the time, we use conditions to execute a particular line of codes or skip them. Let's take a real-world example and understand what I mean. Let's say you went to a shoe shop to buy a shoe, but when you get to the shop, the price for all the shoes at that particular place is more expensive than what you expected. What you do best at that time is leave the store, right? But what if you had the money? You will buy one because you need the shoe.

The condition for you to buy a shoe at that particular store is to have enough money. You don't have enough money means you skip buying the shoe from that store. Just like that, we use conditions along with ‘if’, ‘if...else’, and ‘if...else if' statements to execute or skip certain lines of code.

Let's talk about ‘if’, ‘if...else’, and ‘if...elseif’ statements, but before that, let's discuss Code blocks first.

Code blocks

Cose blocks are nothing but a group of statements that lie in the same block. In most programming languages, code blocks are wrapped within the '{}.' We use '{'to open a code block and'}' to close the block. Some programming languages like python use indentations as code blocks.

Indentation is the space between a file's left corner and the first character in the line. It might be represented as the character space or a tab.

The "if" statement

We use this statement when we have only one alternative, i.e., if the condition testifies to True, execute a code block; if not, skip it. The above example is the perfect example of this.

The "if...else" statement

We use this statement when we have precisely two alternatives, i.e., when a specific condition is met, execute some code block but skip the other and vice versa. One point to note here is that if the condition fails, the second code gets executed automatically.

For example, you know that you have the money that will definitely buy you pants, but your priority is to buy shoes. You go to a shoe store first because that's your priority. If the price of a pair of shoes matches your pocket, you buy the shoe skipping the pair of pants. If not, you buy the pant leaving the pair of shoes because the above condition already failed; you don't get to check any condition here; it will get executed automatically. Either way, you end up purchasing either pair of shoes or a pair of pants.

The "if...else if" statement

Let's take the above example as it is and ask ourselves, "what if the money we have isn't enough to buy a pair of pants?". That's where we need the 'if... elseif' statement because it will allow us to check another condition.

To put it simply, check the price of pair of shoes; if you can afford to buy it, buy it. If not, check the price of pair of pants; if you can afford to buy it, buy it. If not, you end up without buying one since you won't afford them.

We also use conditions to run particular lines of code repeatedly. We will talk about it when we get to the Loops section of this article.

Loops

In the above example, let's say you desperately need to buy pair of shoes so you won't give up after looking at just one store, right? If the price is too expensive at that specific store, you keep looking for other stores until you find a pair of shoes you can afford. When you find one, you will stop searching for another. That's what loops do.

Our condition in this example is, "is the pair of shoes affordable in this store?"; if the answer is no, look for another store and check the condition; if the answer is still no, keep looking for another store and check the condition. When you find a store with an affordable price, you will buy the shoes and stop looking for other stores.

There exist different kinds of loops in programming languages, but the common ones are: for loop and while loop.

Functions

Let's continue with the idea of buying a pair of shoes and say you are busy; you have no time to look for stores and buy shoes. At this time, you ask someone to buy them for you, but that someone has to get the information about the kind of shoes you want, your size, and money from you. If you fail to provide the information and money for that person you asked to do you a favor; you don't get your shoes. You give the necessary information and money to that person, who will go to the stores to buy the shoes and bring the shoes to you. That's what functions do in a nutshell. They will accept some input, perform a set of operations (you can say a block of code) on or using the input, and provide the results or outputs.

One thing to note here is that as the response you will get is different from the person you ask a favor based on the task you asked them to do, the results you will get from functions will also be different based on the operations they perform.

If you ask someone a favor of delivering a message, their response will be yes or no when you ask them, "Have you delivered the message I asked you to deliver?." Functions perform likewise.

Another good point of functions is that whenever you need them, you can reuse them just like you will ask the person you previously requested a favor to buy another pair of shoes whenever you are busy.

In simple terms, functions are a block of codes with a name that we use the name to reuse the block of code. If we encounter a block of codes we need in multiple places in our code, we put them in a function and call them whenever we need them.

We have covered all the terminologies necessary to develop a Pseudocode or Flowchart. We can also easily understand the already built Pseudocode or Flowchart once we finish the rules for Pseudocode and Flowcharts. In this regard, we will see Pseudocode and Flowcharts in our next article.