Post increment operator not incrementing in for loop

前端 未结 5 1712
我在风中等你
我在风中等你 2020-11-28 13:04

I\'m doing some research about Java and find this very confusing:

for (int i = 0; i < 10; i = i++) {
  System.err.print(\"hoo... \");
}

5条回答
  •  广开言路
    2020-11-28 13:20

    i++ will report the value of i, and THEN increment. This also means that you don't need to set i equal to i++, just change to

    for (int i = 0; i < 10; i++) {
    

提交回复
热议问题