loop break

I have a loop which calculates a sum. I need it to stop when it equals 0. [ i have managed to do this with an if and break statement].

BUT if the sum never equals 0, I need the loop to stop when the answer is CLOSEST. I tried using [ if (sum >0) break;] BUT the loop only stopped at the FIRST integer >0, not the integer CLOSEST to zero.

So basically I ahve a loop and I want to search for the lowest integer > 0

I dont HAVE to use a break, if you can suggest something better I will use that

Any help would be greatly appreciated.
thanks
Last edited on
What are your validations in the loop then? There are lots of ways to control a loop statement without using the break keyword. If you post your code, then it'll be easier to walk you through.
Can you put your code so we can figure out a solution? It will be more faster.
stopping a loop when it is closest to 0 would be hard b/c the first answer U get would be the closest to 0.
Topic archived. No new replies allowed.