Java For Loop - insert an element after every n elements

I looked around, but could not find anything suitable - this is in the vtl file, but I think this is the same syntax.

I want to insert something after every n elements, and not replace the nth element of the for loop, which I did by chance, trying to solve the problem. What would be the best way to approach this? Thousands of scrollable elements can exist.

My current code is:

for(var i = 0; i < data.results.length; i++) {
  if(i % 5 == 0){
    //Show the nth element
  }
  else{
    //Display each table result normally
  }
}
+4
source share
1 answer

else. "else" , , if . - ( : ), if-, , .

for(var i = 0; i < data.results.length; i++) {
  if(i % 5 == 0){
    //Show the nth element
  }
  //Display each table result normally
}
+1

Source: https://habr.com/ru/post/1606444/


All Articles