RanLearns
RanLearns

Reputation: 4176

Is there a way to use a block comment on a section that's already commented?

I know you can comment out a whole section of code like so:

/*
line of code
line of code
line of code
*/

But if you already have a /* ... */ section in the code that you are trying to comment, then the */ end of a comment block will close the "greater" comment block I am trying to create.

Example:

/* wanting to comment this big section out
line of code
line of code
line of code
line of code
line of code
line of code
/* this section was already commented out before
line of code
line of code
line of code
*/ this section was already commented out before
line of code
line of code
line of code
line of code
line of code
*/ this last part doesn't get commented out, because the comment stops at previous */

Obviously this isn't a huge big deal, it is not stopping me from getting an app to work properly, but I'm just wondering if there might be some way of commenting out a larger section of code, even if there are already comment blocks in that code.

Upvotes: 1

Views: 5991

Answers (3)

joerick
joerick

Reputation: 16448

I'd frown if I saw it in code, but you can do

#if 0

...code...

#endif

Upvotes: 0

Bijoy Thangaraj
Bijoy Thangaraj

Reputation: 5546

To avoid such a situation, always use // for commenting and use Xcode shortcut to comment a block of code.

The shortcut is cmd + /

Upvotes: 4

Gabriel
Gabriel

Reputation: 328

Highlight the code you want commented out and press "Command" + "/"

Upvotes: 8

Related Questions