Why do this loop stops..!

This is a discussion on Why do this loop stops..! within the C++ Programming forums, part of the General Programming Boards category; I have tried to print the Characters.. but loop stops at 20 as i wanted but next it again ask ...

I think you are just trying to be silly with this. It would be much easier to read if you simply put

if( i == 20 )

Your way works...because 20 / 20 = 1, however this may not be immediately intuitive to another programmer. Anyways, when you are in that if statement look at what you are doing. You print out a line, then you wait for a key press. You never do anything to exit the for loop so it just keeps going. If you want to quit , add a break statement after getch( ); So it may look like this.

I think you are just trying to be silly with this. It would be much easier to read if you simply put

if( i == 20 )

Your way works...because 20 / 20 = 1, however this may not be immediately intuitive to another programmer. Anyways, when you are in that if statement look at what you are doing. You print out a line, then you wait for a key press. You never do anything to exit the for loop so it just keeps going. If you want to quit , add a break statement after getch( ); So it may look like this.

What do i am intending to do with the if condition that if the loop prints 20 values then it must stop and ask to character input so i can check the output of .. all values... because in my program.... i am using <<endl after every "cout" to display the code and the character...

"...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers