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.
(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.
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.