Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8852777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:29:08+00:00 2026-06-14T13:29:08+00:00

I am processing test.c file and trying to count single line comments in it.

  • 0

I am processing test.c file and trying to count single line comments in it.

When I spot two consecutive / characters, I set slc trigger to true.

And when I reach the end of line, I need to set slc trigger to false.

Of course \n character clearly indicates the end of single-line comment.

switch (character)
{
    case '\n':
        slc = false; // single-line comment ended
        break;

But when \n character found, slc could be either true or false.

switch (character)
{
    case '\n':
        if (slc) slc = false; // single-line comment ended
        break;

Is there any difference between these two code blocks?

How should I write?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:29:09+00:00Added an answer on June 14, 2026 at 1:29 pm

    Use the first form. Adding an extra if check which doesn’t affect the functionality of your code, only its readability, is bad practice. You should always write the most concise way possible that doesn’t obfuscate the intention of your code. Since in this case your intention is always for the variable to be false, simply set slc = false.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am processing a flat file, with data in line by line format, like
I'm trying to sign an app made in Processing so I can test it
I am trying to set-up a two step signup process using Devise in Rails
I am trying to write program for parsing and processing text file. After not
I am trying to get the fastspring subscription payment processing set up. I have
I'm trying to test a php file from a C program(...) Basically I have
I am basically processing tweets for a project of mine. I am trying to
I'm processing a xml file and sometimes there are iframes and script tags i
I am trying to use different stripe keys (a credit card payment processing system)
I am trying to import CSV file to SQL server database, with no success.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.