+ 1
Can the statement 'else' be used inside the block of an 'if' statement?
In other words, does 'else' require its own brackets?
4 ответов
+ 5
You can't put the else inside the block of its matching if if that's your question. You can only put it right after the if block.
By the way, if there is only one statement in your block, you don't need to put brackets. This goes for if, else, while, for, etc.
if (condition) {
one_statement;
} else {
another_statement;
}
is equivalent to
if (condition)
one_statement;
else
another_statement;
0
I just tested it. 'else' needs to be in its own curly braces.
0
No .. You can't
0
You have to use else by itself.