+ 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?
31 odpowiedzi
+ 2
use single line comment (//) for inside a multi line comment (/* */)
+ 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.
+ 7
Yes,for multiline comments,like this: /*Coding is fun
*My name is Moses
*stay away from leopards
*they are dangerous
*animous
*/
+ 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
*/
+ 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.
+ 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.
+ 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.
+ 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. 😝
+ 1
@Rrestoring you're right, it's too difficult to understand. All in all, thanks for help! :)
+ 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.
+ 1
/*
I am a boy
//just kiding
really am a girl
*/
+ 1
in a multiple lines comment you can write anything.
you can write any character/alphabet/special symbols etc.
+ 1
for single line comment (//)
and for inside a multiline comment (/* */)
+ 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//
*/
+ 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
+ 1
yes it is
/* programming is cool
//programming is magical
*/
+ 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. :)
0
You don't need to do this.
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
0
Just use some separation characters to improve readability.