Published Sep 7, 2021
4 mins read
799 words
This blog has been marked as read.
Read more
Technology

Think Like A Pro(grammer){} Part4.a Step Further();

Published Sep 7, 2021
4 mins read
799 words

Hello people and welcome to the Part 4 and also, thank you for reading my previous blogs too.

So, now you already know about data types and operators. But this time, it is gonna be a step further to logical statement which help the program to think like we normally do. If you think it to be easy, things will become easy.

As simple as that…

(i) The ‘if-else’ statement.

If you read this, you die, else you don't die. Well, that's all about the if statement😂. The statements provided within the if statement are executed if the condition given returns true, otherwise if the condition returns false, the statements inside the if part is skipped and that in the else part will execute(you can ommit the ‘else’ part, but if there is an ‘else’ part, you cannot ommit the ‘if’ part). There can also be an ‘elseif’ part which can be added to check between different conditions.

2.Loops(while loop, for loop).

Most programming languages have loops which are really important for many uses in programming like if you have to repeat the same process many times with different values each time. The while loop just takes a condition and repeats the code inside it till the condition returns true and the for loop takes a value, takes a condition and a change in the value which gets implemented every turn.

Then there are switch statement, do-while loop, for each loop etc. but they aren't really important for now.

Okay, remember that we are just talking about the basics of programming and all this is just for the starters because I myself am a beginner in programming. And mostly I have learnt C based languages except Python. So, keeping that in mind, lt me introduce you to

Functions.

A function contains codes which can be reused time and again in the program as per need. So you may define a function to calculate the average of a number and reuse it in the code easily. In C based languages a function is mostly defined simply by its name as-

Average(x, y)

{

return (x + y)/2;

}

*Average is just a name which you can keep as per your wish and x and y are parameters which are passed to the function while calling it. Like if we call it in the program as Average(10, 20); here we are passing values 10 and 20 in place of x and y and the function will work upon the values as told, so it would be (10+20)/2 which will be equal to15.

In python, a function is defined using ‘def’ keyword.

Classes

Most common programming languages are based on OOP(Object Oriented Programming) so they work upon classes. Classes are like blueprints for any object which has its own properties. So classes can be declared as new objects every time(which is called instantiation) with their own values for each properties.

For example, you create a class named ‘Vehicle’ with properties company, tyres, speed and persons. Then you instantiate an object named car with values kept as "Ferrari" for company, 4 for tyres, 120 for speed and 4 for persons and then use this object in the program.

Finally an important thing is arrays.

Arrays

I think I should've told you about this before, because it is also a data type but with a few extra steps. Array is a group of objects of similar data type.

In this sample c++ code, vehicles[] is an array, and the element having index 2 is being printed(cout is the statement to print in c++) so aeroplane will be the output (since counting in programming starts from 0).

For example there can be a group of integers or group of strings or maybe a group of objects of the same class created by you. For example as you had created a class vehicle earlier, you can now make many more objects like car, bike, cycle etc. and make an array of them as-

vehicle car, bike, cycle;

vehicle veh[] = {car, bike, cycle};

Here, your class itself is the data type and car, bike and cycle are its objects. Just like you can declare x as int having value 5, you can declare car as vehicle with its own properties.

Well, I think you didn't understand most of the concepts but this was just to increase your curiousity and interest in programming, or maybe just to make you believe that programming is not difficult. And since I wasn't that much into it, I left many concepts since you cannot currently understand them all. So go learn it!

Thank you for reading this blog till the last and…

…follow me

…for a follow back.

12
10
ganga_ambily_gopi 9/7/21, 2:56 AM
Informative ✨
anusha.n.m 9/7/21, 3:44 AM
Nice
yourinnervoice 9/7/21, 6:01 AM
Well written🙂 keep going. Check mine too. Follow for a definite follow back.
akanksha02 9/7/21, 8:41 AM
#monkhood..please go through my blogs too
asadmirza1997 9/7/21, 9:59 AM
👍👍👍👍👍👍👍
mreeduban.goswami 9/7/21, 1:18 PM
Interesting nice
nethra.s 9/7/21, 4:38 PM
👍
thegirlwithsensation 9/9/21, 2:16 AM
Good one. #monkhood
2k_queen 9/10/21, 1:09 PM
Good one #monkhood
lokeshbhandari821 4/13/22, 1:02 PM
Nice Blog Pls read mine too

Candlemonk | Earn By Blogging | The Bloggers Social Network | Gamified Blogging Platform

Candlemonk is a reward-driven, gamified writing and blogging platform. Blog your ideas, thoughts, knowledge and stories. Candlemonk takes your words to a bigger audience around the globe, builds a follower base for you and aids in getting the recognition and appreciation you deserve. Monetize your words and earn from your passion to write.