for loop in thymeleaf

前端 未结 4 1772
伪装坚强ぢ
伪装坚强ぢ 2021-02-18 19:10

How can I do the following (java):

for(int i = 0; i < 81 ; i+=20){
   //Should loop through 5 times!
}

in Thymeleaf?

I\'ve tried thi

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-18 19:22

    I am assuming this is due to the numbers you are using. For your java code, int i = 0; i < 81 ; i+=20 will return i=0, i=20, i=40, i=60 and i=80

    however your following code numbers.sequence( 1, 81/20)} should returns the integers from 1 to 4.05, being 1, 2, 3, and 4.

    The first loop returns 5 results for i, therefore runs 5 times. the second returns only 4 results, so runs 4 times. I would suggest running your sequence starting at 0 to return 5 results as desired.

    If you wanted your java code to mirror the second code, you should change it to: int i = 1; i < 4.05 ; i+=1

    To put it simply, you are running through a loop with different numbers, I suggest changing the second statement to start from 0.

提交回复
热议问题