8:30 in the morning. The starting time of my college. The first thing on my timetable happens to be a SPA practical. SPA is short for Structured Programming Approach. This subject is meant to teach students the basics of programming in the C language.
I was there right on time with all my other friends. We took our seats and waited for the teacher to come. She entered (late as always) and told us all to perform a simple program on do-while loop in C.
In about 5 minutes I completed our program. I was just about to execute my program when one my friend who was sitting beside me (call him friend 1) exclaimed, “Stop! Your program is wrong.”
“What’s wrong?”, I asked.
“You have added a semicolon after the while condition. It is not allowed.”
“It is. This one’s a do-while loop and in this kind of loop, you need to end it with a semicolon.”
Then we had a series of “It has” and “It hasn’t”. I was 100% sure that I’m right because I knew the syntax like the back of my hand. Seeing an opportunity, I said, “OK then. If you are so sure about your answer that no semicolon is needed then let’s have a bet. Whoever wins will treat the other to a “Veg. Thali” in the canteen (a typical Indian dish that costs ₹80).
Eavesdropping on our argument was another friend (call friend 2) who was sitting on the other side of me. He had no idea whether a semicolon has to be added or not but seeing my confidence he took my side and addressing friend 1 he said, “If he wins, you’ll have to treat us both. Agree?”
“All right! Then let’s ask the teacher”, said the friend 1. Now, there were two teachers in the lab. One was the professor who taught us and the other was an assistant who just did the job of inspection. We called the assistant and asked her about that semicolon.
“No you don’t need a semicolon in a do-while loop”, she said. Friend 1 grinned claiming his victory and demanded the treat, but I hadn’t given up yet because I was sure that a semicolon had to be added. I couldn’t just believe that assistant so I called the professor and asked her.
“Yes, of course. It’s a do-while loop and not a while loop so you need to add a semicolon after the while condition”, she explained. The grin on friend 1’s face changed into a huge frown and he had to accept his defeat.
Later, it was decided that in the break time we were to go to the canteen and have our “Thali”s served. Friend 1’s luck wasn’t with him that day. Just a single semicolon made him pay ₹160. And Friend 2 was lucky that he took my side.