Im trying to break a while loop before it goes into the negative numbers but it keeps going past 0 and showing a negative numbers
The problem would be my while loop this is the loop
while(Math.round(housetotal)>0){
housetotal-=o*12;
zx++;
row_data.push([zx,
{v:housetotal, f:'$'+Comma(housetotal)},
]);
if(zx == year || housetotal<=0){
break
}
}
my loop works something like this.
lets say
housetotal = 239,852
o = 1,438
222,596 and continue to count down to -1,732 after 14 loops
im trying to make it stop at the 13th loop which is 15,524 so it doesn’t go into the negative
in my while statement i have if zx which is equal to whatever number i have which in this case is 15 and o*12 is whatever number that comes up multiplied by 12 but in this case is 1,438 x 12 = 17,256
One solution is to check the values after the assignment and break the loop then: