Suppose I'm running a loop and the loop should continue unless I get a garbage value.
So what will be the terminal condition. How can garbage value be checked in if condition?
Dude, you need to explicity define what you consider as valuable information.
What information do you really consider to be valid, so that you can discard the rest as garbage?
For example, if I want my user to specify the no. of humans living on earth, then I can assume for a fact that it will be between 5 billion to 10 billion for this year, taking into account something drastic also happens (nuke, sudden overgrowth).
So, any other value for me is garbage, which I can discard.
On a side note,
I think you're using the wrong language here wiseRehan.
If you don't know the exact value, then you could specify some rules which define what is garbage, for example a negative number might be considered garbage - but that decision is up to you.
can we find out the garbage value without running and printing through program
Sorry, I don't understand the question, if the program is not running, then no values exist at all, there is nothing to look at.
The problem you're facing implies that you're doing something very odd with your code. For example, overflow: when I use a very long loop and increase the value of an integer i beyond INT_MAX then it automatically becomes ...-INT_MAX-1. C++ doesn't detect this automatically, you need to take this into account explicitly.
It's not really a problem, because if this happens then that means something in your code is not functioning properly. There are other high level languages available that detect this automatically. I believe Ada is one example.