How to insert an else-if statement or comment in if-else-if statements with correct indentation?
Hi,
I'm using CLion 1.2.2, and code stype is set to Default.
When I'm trying to insert an else-if statement or a comment between some if-else-if, the automatic indentation looks quite strange to me.
// The if-else-if code.
void foo()
{
int x = rand();
if (10 < x) {
// case 1
}
else if (x < 10) {
// case 3
}
}
// Then, I adds an else-if statement, the indentation goes too far from where I expected.
void foo()
{
int x = rand();
if (10 < x) {
// case 1
}
else if (0 == x) {
// Case 2
}
else if (x < 10) {
// case 3
}
}
// Adding a comment between if-else-if statement behaves in the same way.
void foo()
{
int x = rand();
if (10 < x) {
// case 1
}
else if (0 == x) {
// Case 2
}
// Comment
else if (x < 10) {
// case 3
}
}
Anyone know how to fix it?
Thanks.
Please sign in to leave a comment.
Hi!
Thanks for reporting, I've created the issue in the tracker: https://youtrack.jetbrains.com/issue/CPP-5432. Feel free to comment or upvote.
try this way:
if(...)
{
... ;
}
else if(...)
{
... ;
}
else
{
... ;
}
I think you forgot a semicolon after every statement.