IdeaMonk

thoughts, ideas, code and other things...

Thursday, June 21, 2007

The Killer semicolon ';'

We all know what semi-colon does. ';' it terminates. Exactly!!
But sometimes it terminates good things too like a ruthless terminator. Specially in cases of if..else, and loops - while, do while, for.
Lets see -

';' kills if..else
int main() {
int a=5;
int b=0;

if (a < b);
printf ("b is less than a\n");

return 0;
}
';' kills while loops
int main() {
int a=5;
int b=0;

while (b<5);
b++;

printf ("b = %i\n",b);
return 0;
}
and the tyranny goes on with for and do while loops

Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home