If statements

I have the following hw question:

3. The following statement is designed to check the relative sizes of three integers,which you may assume to be different from each other.
if (x<z) if (x<y) if (y<z) c=1; else c=2; else
if (y<z) c=3; else c=4; else if (x<y)
if (x<z) c=5; else c=6; else if (y<z) c=7; else
if (z<x) if(z<y) c=8; else c= 9; else c=10

The first line of code includes 3 if statements. How do you read this?

I cannot find any shorthand for if statements written this way. I believe it is read as:

if (x<z) AND if (x<y) AND if (y<z) THEN c=1;

can anyone confirm this?
The first pseudo-code is logically incorrect. The if statement can look as

if ( /*...*/ ) { /*...*/ }
else if ( /*...*/ ) { /*...*/ }
else { /*...*/}

You may not write

if ( /*...*/ ) { /*...*/ }
else { /*...*/}
else if ( /*...*/ ) { /*...*/ }

where else and if else are changed.


Thanks Vlad. Your explanation makes perfect sense to me. The assignment was given by my Prof. I will consult with her. Thanks again!
if (x<z) if (x<y) if (y<z) c=1; else c=2

if(x<z && x<y && x<z) c=1;
else c=2;
if (x<z) if (x<y) if (y<z) c=1; else c=2; else
if (y<z) c=3; else c=4; else if (x<y)
if (x<z) c=5; else c=6; else if (y<z) c=7; else
if (z<x) if(z<y) c=8; else c= 9; else c=10


I think that the pseudo-code should be analysed with a stack. the if statement performs push and the else statement performs pop

Topic archived. No new replies allowed.