Why does adding a semicolon after 'for (…)' change the meaning of my program so dramatically?

前端 未结 6 2169
猫巷女王i
猫巷女王i 2020-12-04 04:30

I wrote the following class:

  public class TestOne {
     public static void main(String[] args) {
        int count = 0;
        for (int i = 0; i < 100         


        
6条回答
  •  -上瘾入骨i
    2020-12-04 04:50

    By adding that semicolon, you are declaring the for statement without a block to loop.

    This causes count++ to only be executed once when it's passed, rather than 100 times when it's looped over.

提交回复
热议问题