# Creating a border using ncurses

The biggest question is if it's worth it to use a useless if statement to make the x and y variables local away from the main statement.

    //Unconventional part, make it so that x and y are local variables
if(true){
int x,y;
//set x and y to be the width + height of the terminal
getmaxyx(stdscr,y,x);
for(int i = 0; i < x; i++){
//top border
//bottom border
}
for(int i = 0; i < y; i++){
//left border
//right border
}
}

• You could just have a block; the if(true) could be left out – qxz Nov 26 '16 at 6:12
• @qxz, he wants to make x and y local variables. He asks if it's worth it. I would say that he should just make it a function. – Incomputable Nov 26 '16 at 6:43
• @Incomputable I was just making a comment that you can have a plain block without the if. I agree that I'd make it a function – qxz Nov 26 '16 at 6:44

You can create a block without an if statement. For example, these are equivalent:

{
// some code
}

if (true) {
// some code
}


But it's not a good practice to create blocks like this. It's a code smell, suggesting to wrap // some code in a dedicated function instead.

Anytime you think some neat trick is "unconventional", it's most probably a bad practice. Don't do it, fix it.

In addition to what @janos said:

Your formatting style looks weird. This is because in mvaddch(0,x - 1,'#') there is plenty of space around the - operator, but none around the ,. This commonly suggests that the , binds more tightly than the -, which is wrong.

So either use no space at all or use a space after the comma as well.