0

When your code gets longer, how do you check your curly braces?

I am writing my first "longer" piece of code (approx 200 lines) and find it difficult to check that I have all my braces closed properly. How do you do it?

FTR, I have a quad nested loop situation. I've been removing the "guts" from my program,printing it out, and then going through and matching all my braces but there must be an easier way.

I am getting an expected identifier error and suspect the braces.

Thanks!

0

If you are following the CS50 Style Guide, particularly in regard to curly braces (each on its own line) and indentation, it should be easy to spot missing braces.

If you are using the CS50 IDE (which I assume you are if you are taking CS50x), know too that you can click on the line number for any open curly brace { and the editor will collapse everything within that section. If you see that you have collapsed more than expected, you can check for the missing }.

5
  • Actually I did not know about that tip. It's exactly what I needed. No more printing and counting! Clicking on the line number does not work but double clicking on the opening brace or within the pair will highlight the content. So that works just as well. Thanks!
    – Lee Gainer
    Dec 19 '16 at 21:55
  • Yes, that works too. :) As for the collapsing, hover just to the right of the line number and you should see a little arrow. Click that. Alternatively, other methods under Edit > Code Folding in the menu.
    – curiouskiwi
    Dec 19 '16 at 21:58
  • You can also select/highlight a curly brace and the IDE will mark the matching brace. And, if you double click on a curly brace, the IDE will highlight the entire block of code from the opening curly brace to the closing brace, including any curly brace pairs that are nested inside.
    – Cliff B
    Dec 19 '16 at 22:07
  • Terrific, thanks Cliff! Curious, I do not have a Edit > Code Folding option. i think my IDE is different than yours. Thanks for the input though.
    – Lee Gainer
    Dec 20 '16 at 17:48
  • @LeeGainer if you are using the CS50 IDE, go to View and untick the "Less Comfortable" setting at the top. That will give you the full menus, and you should see the Code folding option in Edit.
    – curiouskiwi
    Dec 20 '16 at 21:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .