# Thread: Flow diagram If Elseif - Else statement

1. ## Flow diagram If Elseif - Else statement

I have made it flow diagram and I want understand how it would be look in code structure

What would be the structure of the code for this function flow diagram ?

Code:
```#include<stdio.h>

int main ()
{

if ( expression1)
{
printf("statment 1");
}

else
{
printf("statment 2");
}

return 0;

}```

2. What's your best try?

3. Maybe if you gave each expression in your diagram a different name, it would help when you saw the code.

4. Originally Posted by laserlight
What's your best try?

I shown my best making diagram I don't even know if this can happen real once I get the idea, I will try to make more diagrams

Originally Posted by Salem
Maybe if you gave each expression in your diagram a different name, it would help when you saw the code.

5. Like so - for you to finish off...
Code:
```if ( E1 ) {
if ( E2 ) {
S2;
} else {
S21;
}
} else {
if ( E3 ) {
} else {
}
}```

6. Originally Posted by Salem
Like so - for you to finish off...
alright I am converting logic into code but I am surprised that you did not use the else if statement

Code:
```#include<stdio.h>

int main ()
{
int n = 3;

if ( n == 1 )
{
if ( n == 2 )
{
printf(" 2 \n");
}
else
{
printf(" 23 \n");
}
}
else
{
if (n == 3 )
{
printf(" 3 \n");
}
else

{
printf(" 4 \n");
}
}

return 0;
}```
3

7. > but I am surprised that you did not use the else if statement
That would imply that you have more than true/false at some level.

Code:
```if ( n == 1 ) {
} else if ( n == 2 ) {
} else {
}```

Popular pages Recent additions