Nested if-else behaviour without braces

后端 未结 4 1342
旧巷少年郎
旧巷少年郎 2020-12-03 14:08

Consider the following unformatted nested if-else Java code

if (condition 1)
if (condition 2)
action 1;
else
action 2;

My ques

4条回答
  •  渐次进展
    2020-12-03 15:00

    From the documentation:

    The Java programming language, like C and C++ and many programming languages before them, arbitrarily decrees that an else clause belongs to the innermost if to which it might possibly belong.

提交回复
热议问题