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
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?Originally Posted by YuminZhao
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
> 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 } }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Perhaps you used many if's when you should have been using a switch statement. We wont ever know without seeing the code.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"