I'm writing a small program that count the lines of code. Here is the definition of a line of code: - any line that contains code necessary for the program to function. - blank line is not a line of code. - comment is not a line of code. - if there's code and a comment right after on the same line, it counts as well.
So I have this piece of code (simple if statement):
found = lineRead.find("/*");
if(found != string::npos)
{
found = lineRead.find("*/");
if(found != string::npos)
inComment = false;
else
inComment == true;
}
return inComment;
Assume that
String lineRead = "cout<<\"helloworld!\";/*blockcomment"
Bool inComment (is true if the previous line didn't have end block comment token)
So my program reaches the first if statement because it found /*
in that line, looks for */
, goes to the second if statement then jumps straight to the return statement without changing inComment
(which is supposed to be set to true
because the text on the next line is still inside the block comment).
Anyone know why that is?
if/else
could be replaced byinComment = (found == string::npos);
return (found == string::npos);
.inComment
if the outerif
condition is false?