© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
1 reply
kaplumbanecdet

Confused about if statements

int sumPos = 0;
int sumNeg = 0;
bool isEmpty = false;
if (input is [])
{
    Console.WriteLine("[] you entered an empty array");
    isEmpty = true;
}
else //the line I talk about when I add else if(isEmpty = false)
{
    Debug.WriteLine("isEmpty = false");
    foreach (int i in input)
    {
        if (i > 0)
        {
            sumPos += i;
        }
        else if (i < 0)
        {
            sumNeg += i;
        }
    }
    Console.WriteLine("Sum of the positives: " + sumPos + "\nSum of the negatives: " + sumNeg);
}
        
int sumPos = 0;
int sumNeg = 0;
bool isEmpty = false;
if (input is [])
{
    Console.WriteLine("[] you entered an empty array");
    isEmpty = true;
}
else //the line I talk about when I add else if(isEmpty = false)
{
    Debug.WriteLine("isEmpty = false");
    foreach (int i in input)
    {
        if (i > 0)
        {
            sumPos += i;
        }
        else if (i < 0)
        {
            sumNeg += i;
        }
    }
    Console.WriteLine("Sum of the positives: " + sumPos + "\nSum of the negatives: " + sumNeg);
}
        


when I add else if instead of else the condition is met even in the debugging but it skips the else if statement
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

If statements
C#CC# / help
3y ago
Branching if statements
C#CC# / help
3y ago
✅ multiple if statements
C#CC# / help
3y ago