Java print result every 10th iteration of a for loop -


i'm trying write simple function print message every 5th or 10th iteration of for loop. example:

in code want print i each tenth iteration:

private void calc() {     int broadcast_by_percent = 100 / 10;     int calculate = 0;     (int = 0; <= 100; i++) {         if (i == calculate) {             calculate = broadcast_by_percent + 10;             log.e("i:= ", + "");         }     } } 

why use if statement while can using for loop specific step, here's code:

int step = 10; (int = 0; <= 100; i+=step) {     log.e("i:= ", + ""); } 

the instruction run each 10th index, , can specify step need.

here's demo.

edit:

and make sure take multiples of step (avoid zero) start loop step:

int step = 10; (int = step; <= 100; i+=step) {     log.e("i:= ", + ""); } 

notice i=step here.


Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -