Cleaning up code -- grouping parts in {}

Lets say I have a ton of valid if statements as follows:

1
2
3
4
5
6
     if (){
     } 
     if (){
     } 
     if (){
     } // stops at a 100 if statements      


would it be okay if I grouped it inside of {} like...

1
2
3
4
5
6
7
{
     if (){
     } 
     if (){
     } 
     if (){
} 

Last edited on
Yes you can do that. You can add as many {brace} levels as you want.


Though 100 if statements is questionable design.... and I'm not sure if separating them into sections is how I would clean that up.
Oh, don't worry; it's all hypothetical. I was just thinking of ways to group my code once it stops being small and simple. I wouldn't want to scroll up and down thousand lines of code when it's okay to add braces to minimize/hide the code.
If you have thousands of lines of code in a function, adding extraneous braces isn't going to be much help. Instead, keep your functions small and focused on the one thing they should be doing.
Topic archived. No new replies allowed.