The reason of computer programming

Share this post: 

People do computer programming. Some do it good while others get frustrated.

First you should know why you do programming? Because you want the machine to give output according to your need. For example, you want to see all the prime numbers in a given range on the computer screen. You enter the range, but nothing happens. Because the machine is a stupid one and do not understand what you are talking about. You ask it to hurt somebody for no good and it will do it. You ask it to destroy itself and it will do that exactly without hesitation.

Now, you write a program in its language (not our human language). The computer must be able to read and understand your statements without any confusion or ambiguity. So you have to check your statements thoroughly before submitting the document to the computer.

Consider the following snippet in C

                for(i=0 ; i>=0 ; i++)

                {

                             //No statement

                }

The loop block has no statement inside with no upper limit. The controller of the loop is the variable i.

  1. The starting value of i is 0, that’s fine.
  2. The condition is “i should be greater than 0″.
  3. The increment of i will be by 1 every time the execution of the body statement completes.

The loop starts with i‘s value 0 and keeps increasing by 1. And every time the execution of the body statement completes, it meets the condition as TRUE. Consequently the statement is executed again, and again and again.

 



It will go on and on. It will never get irritated and raise complaint – “Hey, why are you making me run this loop that has no specific job?” Because I told you that it is a stupid machine.

Now I hope you have got my point. You have to make the computer understand properly what to do. Actually you have one thing in your mind and coding something else that your eyes are overlooking.

The trick is – BECOME YOURSELF THE COMPILER. Assume that you have got the code instead of the compiler. This is called Dry Run. Now by reading that code, find out the output. You will win for sure.

Share this post: 

 

admin