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 8147859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:29:44+00:00 2026-06-06T14:29:44+00:00

I initially had the following code: Boolean successCheckPoint = false; Boolean failureCheckPoint = false;

  • 0

I initially had the following code:

        Boolean successCheckPoint = false;
        Boolean failureCheckPoint = false;
        Boolean timeFound = false;

        foreach (var row in auditRows)
        {
            timeFound = row.Text.Contains(sCurrentTime) || row.Text.Contains(sLenientTime) || row.Text.Contains(sLenientTime2) ? true : false;

            if (timeFound)
            {
                successCheckPoint = row.Text.Contains("Web User Login Success") && !successCheckPoint ? true : false;
                failureCheckPoint = row.Text.Contains("Web User Login Failure") && !failureCheckPoint ? true : false;
            }                                

        }

But I found that in later iterations of the foreach, even if the successCheckPoint or failureCheckPoint booleans had been set to true, they’d end up getting set to false because of the way that I’d set up the assignment.


Example problem

First Iteration

  1. timeFound is true
  2. successCheckPoint is false
  3. row.Text does contain the text I want
  4. successCheckPoint is indeed false
  5. successCheckPoint set to true

Second Iteration

  1. timeFound is true
  2. successCheckPoint is true
  3. row.Text does not contain the text I want
  4. successCheckPoint is not false
  5. successCheckPoint set to false

So to fix the problem, I changed the code into this:

        Boolean successCheckPoint = false;
        Boolean failureCheckPoint = false;
        Boolean timeFound = false;

        foreach (var row in auditRows)
        {
            timeFound = row.Text.Contains(sCurrentTime) || row.Text.Contains(sLenientTime) || row.Text.Contains(sLenientTime2) ? true : false;

            if (timeFound)
            {
                if (!successCheckPoint)
                {
                    successCheckPoint = row.Text.Contains("Web User Login Success") ? true : false;
                }

                if (!failureCheckPoint)
                {
                    failureCheckPoint = row.Text.Contains("Web User Login Failure") ? true : false;
                }
            }                                

        }

This does what I want, but it feels like there should be a better way to go about accomplishing this type of behavior. Is there any way to set things up so that once a boolean is set to true, it won’t get changed back to false for future iterations?


Correct Behavior

First Iteration

  1. timeFound is true
  2. successCheckPoint is false
  3. row.Text does contain the text I want
  4. successCheckPoint is indeed false
  5. successCheckPoint set to true

Second Iteration

  1. timeFound is true
  2. successCheckPoint is true so skip re-evaluation

Sorry if this is still confusing. I can explain a little bit more if necessary.


Edit: Now that I think about it I don’t really need the ‘? true : false’ parts for this code.

New Code:

        Boolean successCheckPoint = false;
        Boolean failureCheckPoint = false;
        Boolean timeFound = false;

        foreach (var row in auditRows)
        {
            timeFound = row.Text.Contains(sCurrentTime) || row.Text.Contains(sLenientTime) || row.Text.Contains(sLenientTime2);

            if (timeFound)
            {
                if (!successCheckPoint)
                {
                    successCheckPoint = row.Text.Contains("Web User Login Success");
                }

                if (!failureCheckPoint)
                {
                    failureCheckPoint = row.Text.Contains("Web User Login Failure");
                }
            }                                

        }

Thanks for the help everyone! Here’s the version of the code I’ve settled on:

        Boolean successCheckPoint = false;
        Boolean failureCheckPoint = false;
        Boolean timeFound = false;

        foreach (var row in auditRows)
        {                            
            if (row.Text.Contains(sCurrentTime) || row.Text.Contains(sLenientTime) || row.Text.Contains(sLenientTime2))
            {
                successCheckPoint |= row.Text.Contains("Web User Login Success");
                failureCheckPoint |= row.Text.Contains("Web User Login Failure");
            }

            if (successCheckPoint && failureCheckPoint)
            {
                break;
            }

        }
  • 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-06T14:29:46+00:00Added an answer on June 6, 2026 at 2:29 pm

    You can use the OR assignment operator |=:

    bool successCheckPoint = false;
    bool failureCheckPoint = false;
    
    foreach (var row in auditRows)
    {
        if (row.Text.Contains(sCurrentTime) ||
            row.Text.Contains(sLenientTime) ||
            row.Text.Contains(sLenientTime2))
        {
            successCheckPoint |= row.Text.Contains("Web User Login Success");
            failureCheckPoint |= row.Text.Contains("Web User Login Failure");
        }                                
    }
    

    a |= b; is short for a = a | b;. So if a is already true, it stays true. If a is false and b is true, then a becomes true. Otherwise, a remains false.

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

Sidebar

Related Questions

Initially I had the habbit of directly writing the php code in the <?php
My code base initially was written in ruby. It had a rakefile.rb file to
I had some problem understanding the following line of code. What exactly does it
I've initially had two branches: master A---B---C \ fork D---E---F---H---I So I wanted to
I recently wrote a program that used a simple producer/consumer pattern. It initially had
Initially I had designed this flash based navigation menu for my website, after going
Initially I had a method in our DL that would take in the object
For this assignment I had to create my own string class. I initially wrote
I currently have the following code: function render(url1, url2, message) { utility.messageBoxOpen(message); $.getJSON(url1, function
I'm doing the following code to filter a list of objects before it gets

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.