Home > Software design >  to limit the limit count variable to fixed value
to limit the limit count variable to fixed value

Time:12-16

I want to execute some code based on value in limit count, but I want to limit its value to 20000 max. for eg if limit count passed is 50000 then run the code three times with values as 20000,20000,10000 also if limit count is 10000 then run it as is

CodePudding user response:

I guess, you need smth like that:

int limit = 50000;
int maxLimit = 20000;

while (limit > 0) {
  callYourCode(Math.min(limit, maxLimit));
  limit -= maxLimit;
}
  • Related