For Loops and stopping conditions

前端 未结 4 1846
孤城傲影
孤城傲影 2021-01-29 14:14

Can anyone explain why the answers are what they are please? The first one i guess its because the stopping condition is already reached so it skips the statement but question 1

4条回答
  •  野性不改
    2021-01-29 14:38

    In Question 13 :

    for (n = 4; n > 0; n--);

    the loop executes directly. So, It just decreases the value of n, and didnot enter to the next statement until it completes its execution. So, here it won't come to statement until it completes its execution. At the End of execution value of n is 0. So, when it comes to statement

    System.out.print(n);

    value of n is 0 , so the output of the program is 0

提交回复
热议问题