Hello all:
I am coding a program, due to the situation is complicated, I used
several "if" in a row. I found that it is not allowed to use "if" repeatedly. Is this true? What's the rule to use "if"? --Zhao
Printable View
Hello all:
I am coding a program, due to the situation is complicated, I used
several "if" in a row. I found that it is not allowed to use "if" repeatedly. Is this true? What's the rule to use "if"? --Zhao
Perhaps you simply made a syntax error. Show the smallest and simplest program that you expect to compile but which demonstrates this error. What is the error message, anyway?Quote:
Originally Posted by YuminZhao
> Is this true? What's the rule to use "if"?
From a language point of view - it's fine to string as many if statements together as you want.
Your local coding standards from your boss/tutor may however vary.
Perhaps you should post some kind of example.
Perhaps you're meant to simplify things as well, such as
becomesCode:if ( foo && bar ) {
// stuff
}
if ( foo && baz ) {
// stuff
}
Code:if ( foo ) {
if ( bar ) {
// stuff
}
if ( baz ) {
// stuff
}
}
Perhaps you used many if's when you should have been using a switch statement. We wont ever know without seeing the code.