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

前端 未结 13 1740
情书的邮戳
情书的邮戳 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 05:02

    If you have a for loop like this:

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

    In this loop you are using shorthand provided by java language which means a postfix operator(use-then-change) which is equivalent to j=j+1 , so the changed value is initialized and used for next operation.

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

    In this loop you are just increment your value by 3 but not initializing it back to j variable, so the value of j remains changed.

提交回复
热议问题