Skip to content
Advertisement

to limit the limit count variable to fixed value

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

Advertisement

Answer

I guess, you need smth like that:

int limit = 50000;
int maxLimit = 20000;

while (limit > 0) {
  callYourCode(Math.min(limit, maxLimit));
  limit -= maxLimit;
}
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement