How to make for loops in Java increase by increments other than 1

前端 未结 13 1764
情书的邮戳
情书的邮戳 2020-12-24 04:33

If you have a for loop like this:

for(j = 0; j<=90; j++){}

It works fine. But when you have a for loop like this:

for(j          


        
13条回答
  •  不知归路
    2020-12-24 04:57

    for(j = 0; j<=90; j = j+3)
    {
    
    }
    

    j+3 will not assign the new value to j, add j=j+3 will assign the new value to j and the loop will move up by 3.

    j++ is like saying j = j+1, so in that case your assigning the new value to j just like the one above.

提交回复
热议问题