+ 8

Is it possible to create a comment inside another one?

When I have a situation like this /* this {is: first commented part;} /*this is one more comment*/ this2 {is: second commented part;} */ I often have the situation like this. I use comments for explaining difficult parts of the code. Then if I have to turn off for a time this part of code (already with the comments), I'd like to just write "/*...*/" . Do I really need to create a lot of different comments?

28th May 2017, 7:48 PM
Alexandra Tkachenko
Alexandra Tkachenko - avatar
31 odpowiedzi
+ 2
use single line comment (//) for inside a multi line comment (/* */)
28th May 2017, 9:06 PM
Gurpreet Singh
Gurpreet Singh - avatar
+ 14
Just for clarity...no nesting. When you do this: /* The code (comment) parser switches modes, looking for (and only for): */ You can /* /* /* /* to your heart's content--the extras are all considered part of the comment--but the very first time you */...any additional 'end' (without a new 'start') is a syntax error. CSS may continue parsing, accept further CSS (the styling engine is not necessarily going to behave like the scripting engine)...and treat the extra end's as garbage (or just stop; depends on the engine). Javascript often kills all further script execution in the current block.
31st May 2017, 2:01 PM
Kirk Schafer
Kirk Schafer - avatar
+ 7
Yes,for multiline comments,like this: /*Coding is fun *My name is Moses *stay away from leopards *they are dangerous *animous */
28th May 2017, 8:36 PM
John Ita
John Ita - avatar
+ 4
Everything inside the multi-lined comment isn't ran anyway. Put whatever you want in there. /* 1) this is cool 2) next line 3) * * or do this = = or do this */
28th May 2017, 9:11 PM
Rrestoring faith
Rrestoring faith - avatar
+ 4
Yes.In CPP you can do it like this: /* Comment 1 // Comment 2 Comment 3 . . . */ But Normally It isn't used cause it may confuse you.
6th Jun 2017, 1:12 PM
keivan Ipchi
keivan Ipchi - avatar
+ 2
@Alexandra if you often have this problem you should do like @Alphonso gives an example of and just use // for commenting code and then you will be able to use /* ... */ for debugging.
31st May 2017, 5:11 AM
Magne Tufte Bøyum
Magne Tufte Bøyum - avatar
+ 1
@Alexandra The things that get commented is everything from the first /* to the first */. So nothing past your first */ is in a comment to begin with. The /* on the 3rd commented line does nothing. This would make your last */ throw an error, since it has no actual /* before it.
28th May 2017, 9:27 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
Yes but it throws an error. https://code.sololearn.com/W15XH0a9SIRt/?ref=app If it did not throw an error, the background in this code would be red. Remove the 1st */ and the background will change as it should. The first /* does nothing as it is commented. (In the css section) Edit: Nvm. I assumed you also meant the code would run after the last */. I'll stop talking now. 😝
28th May 2017, 9:46 PM
Rrestoring faith
Rrestoring faith - avatar
+ 1
@Rrestoring you're right, it's too difficult to understand. All in all, thanks for help! :)
28th May 2017, 10:10 PM
Alexandra Tkachenko
Alexandra Tkachenko - avatar
+ 1
the problem is that the nested comment have no effect since it was commented already so it does work but it would just confuse you in the future. just stick with the standard way of using comments but if you find it helpful to you then go a head considering that you're not working with a team.
30th May 2017, 8:12 PM
Oussama Bouchareb
Oussama Bouchareb - avatar
+ 1
/* I am a boy //just kiding really am a girl */
30th May 2017, 11:13 PM
Alphonse Wiraker
Alphonse Wiraker - avatar
+ 1
in a multiple lines comment you can write anything. you can write any character/alphabet/special symbols etc.
31st May 2017, 3:43 AM
Bhupinder Singh
Bhupinder Singh - avatar
+ 1
for single line comment (//) and for inside a multiline comment (/* */)
31st May 2017, 3:53 PM
Karthik Swarnkar
Karthik Swarnkar - avatar
+ 1
Though we may not nest a comment, but it us possible in multi line comment. We can put a single line comment inside a multiline comment. For example, /* //single line comment// */
1st Jun 2017, 4:44 AM
Sandhya Rani
Sandhya Rani - avatar
+ 1
Nope it is not possible to nest comments but, in c and c++ , you can use preprocessor directives such as #ifdef to, sort of, remove a part of a code. Just do a google search learn more about this
1st Jun 2017, 8:35 AM
Sarthak Dixit
Sarthak Dixit - avatar
+ 1
yes it is /* programming is cool //programming is magical */
2nd Jun 2017, 4:58 PM
Prince
Prince - avatar
+ 1
You can nest single line comments inside the multi line comments. For example: /* Nesting of comments //Nest Single lines */ But you cannot nest multi line comments within each other because when you write the opening comment character /* it has to be closed by using */ before you open another comment otherwise it would generate an error. Hope that helps. :)
7th Jul 2017, 5:51 AM
Reeya Patel
Reeya Patel - avatar
0
You don't need to do this.
28th May 2017, 8:05 PM
Илья Карпенко UA
Илья Карпенко UA - avatar
0
@Rrestoring Not exactly. If I have something like this /* 1st line 2nd line /*3rd commented line*/ 4th line 5th line ... */ 4th, 5th etc. lines are running
28th May 2017, 9:17 PM
Alexandra Tkachenko
Alexandra Tkachenko - avatar
0
Just use some separation characters to improve readability.
31st May 2017, 4:26 AM
Alexander Lavrenko
Alexander Lavrenko - avatar