C
C#7h ago
murns

Nested else if | help

Hi, im new to C# and am a bit confused. What is the difference between a if statsment with a nested if-else and a if-elif-else structure?
5 Replies
Jimmacle
Jimmacle7h ago
if you mean
if (condition1)
{

}
else
{
if (condition2)
{

}
}
if (condition1)
{

}
else
{
if (condition2)
{

}
}
vs
if (condition1)
{

}
else if (condition2)
{

}
if (condition1)
{

}
else if (condition2)
{

}
murns
murnsOP7h ago
?
Jimmacle
Jimmacle7h ago
then nothing, really, assuming you are only putting code in the true paths for each
murns
murnsOP7h ago
right ok that i thought so
Jimmacle
Jimmacle7h ago
the first one gives you a place for code to run if condition1 is false but you haven't checked condition2 yet, that's it

Did you find this page helpful?