I STILL don't understand why you think this is so evil....
Or did you, perhaps, miss the part in message #8 where I agreed with you?
Don't tell them to rewrite their loop, just tell them to initialize their variables before they use them. He's not going to understand why he's rewriting his loops all the time, if he doesn't understand that he simply could have avoided the whole thing, if he would have simply initialized the variable to some value before he started fiddling with it. (I know that, and you know that, and I know that you know, and you know that I know. But HE doesn't know, and he was told "the fix is to rewrite your loop". It's not. It's to initialize his variables before he checks their value. Rewriting the loop has a side effect of fixing the issue - the actual fix is assigning a value to the variable before you start checking the variable for values.)
He needs to get the point that he should be initializing it, not that he should be rewriting his loops. The loop is irrelevant. He encountered the problem because he tried to see what was in the variable, before he gave the variable a value. Teach good fundamentals. Assign a variable a value before you check to see what value a variable has.
I am pedantic by nature when it comes to explaining or having things explained. You should know why something happens, not just how to avoid it.
"Try it like below.... The problem is that you were testing ch before it had any legitmate value assigned..."
Now as I see it he has 3 choices here...
1) Initialize the variable explicitly... char ch = 0;
2) Make a quick change in his loop so he's not testing an uninitialized variable.
3) Write an entirely different loop.
I chose #2 and explained why I chose #2... Why is this a problem?
Ok you win.
Guys, relax ! :)
The OP hasn't even been around to check this interesting debate.