Loops & Conditionals Explained!

Loops & Conditionals Explained!

ยท

2 min read

A blog on the basics of Programming...

Designing the algorithm is one of the jobs of a programmer.

The algorithm is nothing but the sequence of program execution.

Conditional statements help us to take various decisions on the go while designing the algorithm.

  • If my cat is hungry, then she will rub my leg.
  • If a polygon has exactly four sides, then it is a quadrilateral.

These are some of the examples of conditional statements, we use something similar in the Programming as well.

if (the number is even) then print "Even number"

else print "Odd number"

it is one example of a conditional statement where we check whether the number is even or odd.

We can code it using different programming languages.

Suppose there is a requirement to write certain instructions repetitively then we use loops,

Let's go back to our RoboX example from the previous blog,What is Programming?.

Here we gave some instructions to RoboX to go right and down repetitively, what if we have 1000 blocks? do we write them 1000 times? the answer is NO!!!

Here we use the loops to perform this repetitive task.

3.png

See in the example we used a loop to perform 4 sets of right and down moves.

We can code this similar thing in any programming language.

I tried to give you a sense of conditionals and loops because Programming is learning how to think instead of writing code.

See how easy it is to understanding and learn to Program... ๐Ÿ˜

For more such posts don't forget to follow...

ย