Learn concepts, not anything else

Learn concepts, not anything else

Today, I'm going to talk about programming concepts. As you walk down the path of programming, you'll gradually realize something important: Everything is repetitive, but there are a set of fundamental concepts that, once mastered, can help you become proficient in any programming language.

In the early days of learning programming, when our instructor began teaching problem-solving algorithms and explained various problems in a conversational tone, we didn’t quite understand what he was doing. We couldn’t grasp the purpose. But soon enough, we realized that what we were actually facing was a mindset—a structured approach to solving problems.

In this approach we call programming, there are a set of concepts that are shared across all languages. What we do as programmers is essentially expressing problem-solving strategies using these programming concepts and of course, leveraging the power of the language we’re working with.

Let me give you an example to help clarify the idea. Suppose we want to take a number from the user and check whether it’s even or odd.

Here’s how you might say it in plain language:

1- Display a message to the user asking them to enter a number;
2- Take the number entered by the user and store it in a variable called a;
3- Calculate the remainder of the number in variable a divided by 2, and store it in variable b;
4- If the number stored in variable b is greater than 0, then 
         print: "The number a is an odd number.";
   Else,
         print: "The number a is an even number.";

Regardless of whether the above algorithm is optimized or not, it conveys several core programming concepts that you’ll encounter in every programming language. It doesn’t matter which language you’re working with—these concepts are always present, though with some variation in syntax and detail.

The First Concept: Variables

The first concept is the variable. As the name implies, a variable is something that constantly changes. Its contents can be quickly accessed and modified, and it is usually stored in RAM.

Based on what we know about RAM and how it functions, anything stored in this memory is lost when the program ends, the computer shuts down, or similar events occur. Therefore, variables are temporary storage locations used to hold values during the execution of a program.

So here’s what I want to say today: Programming is nothing more than dealing with a set of fundamental and essential concepts. It doesn’t matter which language you’re working with. It doesn’t even matter how familiar you are with the functions or classes of a specific language.

What truly matters is your approach to solving problems—the final product or solution you create.

Another important concept in the above program is conditional structures. In essence, you're saying: "If this happens, do that; and if something else happens, do something else." These "if" statements are actually decisions—choices your program makes based on different conditions.

The concept of conditional structures is always present in programming. Even if you’re writing code in an object-oriented style, you’ll inevitably need to use these structures in certain cases or within specific methods to express decisions.

It doesn’t matter which programming language you use. It also doesn’t matter how conditional logic is written or formatted in that language. What matters is that there exists a concept called a conditional structure, which allows us to instruct the computer: "When faced with a or multiple possible paths—here’s the one to follow until the end."

That’s what a conditional structure is all about.

Another structure—or concept—that exists in programming is looping structures. Let’s look at an example to help you understand it better.

Let’s say you want to turn an LED on and off five times, with a 1-second delay between each action. This is similar to blinking. Now, I'll write the algorithm as follows:


1- Turn off the LED, and initialize a variable named i with the value 1;
2- While i is less than 6, do the following:
         Turn on the LED;
         Wait for 1 second;
         Turn off the LED;
         Increment i by one;

There are two programming concepts present in the example above. The first is the looping structure. As you can see, we’re saying: "While an index is less than a certain value, keep performing a set of actions".

This structure ensures that turning the LED on and off, waiting for 1 second between them, and incrementing the counter all happen five times.

The group of instructions inside this loop is called a block. That is, the block—or the set of instructions within the loop—is repeated a specific number of times.

Another concept present in the example above is names. When we define a variable, we assign a name to it. For instance, in the example, I said: "Define a variable named i". This means: "Reserve a location in RAM, give it the name i, and store the value 1 in it".

Think of it like bringing in a box, labeling it i, and placing the value 1 inside.

The names that users assign to variables, functions, or user-defined methods in a program are called identifiers.

Again, it doesn’t matter which programming language you use—looping structures are always present. The way they’re defined may vary from one language to another, but this is a structure that always exists, regardless of the syntax.

Now, take a look at the following program code and tell me which structure is used in each step.

$i = 0;
while ($i < 5) {
   if ( $i <= 3) {
      echo("Hi <br /> ");
   }else{
      echo("GoodBye");
   }
   $i++;
}

Concept: Variable

$i = 0;

A variable named $i is defined and initialized with the value 0. This variable is used to count the number of loop iterations.

Concept: Loop Structure

while ($i < 5) {

A while loop that continues to execute as long as the condition $i < 5 is true. This structure allows the block of code inside the loop to run multiple times.

Concept: Conditional Structure

if ( $i <= 3) {
   echo("Hi <br /> ");
}else{
   echo("GoodBye");
}

A decision is made based on the value of $i: if it’s less than or equal to 3, it prints "Hi"; otherwise, it prints "GoodBye". This part demonstrates logical decision-making in the program.

Concept: Increment

$i++;

The value of the variable $i is increased by one. This line is essential for controlling how many times the loop runs.

This loop runs 5 times (i = 0 to i = 4), and the output will be:

Hi <br />
Hi <br />
Hi <br />
Hi <br />
GoodBye

Now, let me present a flowchart of the program.

Flowchart

Yes. In the code above, we have a loop structure that executes five times, and within each iteration, a decision structure is evaluated. In the first step, the variable i is initialized to 0. Since it is clearly less than 3, the output "Hi" is printed during the first execution. Then, i is incremented by one.

Since i is still less than 5, the loop continues and "Hi" is printed again. In the third step, i equals 2, which is still less than 5 and not greater than 3, so "Hi" is printed again. In the fourth step, i equals 3, which is not greater than 3, so "Hi" is printed once more. In the fifth step, i equals 4. Since this value is still less than 5, the loop continues, but now i is greater than 3, so "GoodBye" is printed.

Finally, i becomes 5. The loop condition requires i to be less than 5, but now that i equals 5, the loop does not execute a sixth time and exits. At this point, the value stored in the memory location associated with i is 5. If the program ends here and no further code is executed, the portion of RAM used to store i is typically released.

The loop structure above, or any other similar structure, works in the same way. In the example above, we have a counter whose value is constantly checked. In fact, the loop condition is always evaluated at the beginning of the loop, and if the condition is met, the code inside the loop is executed. Of course, this is not always the case—there are conditions that ensure the loop runs at least once. But that’s not the point. What matters is that the concept of repetition exists and is used in programming, regardless of which language you’re using.

So, what I emphasized to you today is the importance of learning the fundamental and essential concepts of programming. The use of these structures exists in every language, and instead of relearning the structure itself, you should focus directly on learning how to apply the concept in that particular language.

I hope you’ve grasped the message and that I’ve been able to convey the essence and true meaning of programming to you.

Posted Using INLEO

0.10099844 BEE
0 comments