Saturday, March 12, 2011

STORIES ON C PROGRAMMING

Let us discuss a story or practical working of a while and do while loops.

While loop story

Nary was getting late,as he had to go to a movie with his friend at nearby movie theatre.He was stuck with his tuition master.He was punished ,to write whatever his master said on a paper up to 6'o clock , and the movie was at 6.15.
So while writing,he was seeing the clock,listening to his instructor(master) and was in urge to go out as early as possible.

So let us compare some similarities between this story and the while loop.Here the boy is the program,the master or instructor is the condition in the brackets and his tendency to go out is the tendency of the program to come out of the loop.

The while loop is an exit control loop.Which means it can control when the program should go out.The boy here is waiting for 6'o clock time,similarly the program wants to get out of the loop as soon as the condition is over.

Once 6'o clock is over he will be able to go out.Similarly the program will be out of the loop when the condition on while loop is over.

I hope you all will like this post... the next post will be about the do while loop which is an entry control loop

No comments: