Is it limited of using "if"?

This is a discussion on Is it limited of using "if"? within the C++ Programming forums, part of the General Programming Boards category; Hello all: I am coding a program, due to the situation is complicated, I used several "if" in a row. ...

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    12

    Is it limited of using "if"?

    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

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Quote Originally Posted by YuminZhao
    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.
    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?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > 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
    Code:
    if ( foo && bar )  {
      // stuff
    }
    if ( foo && baz ) {
      // stuff
    }
    becomes
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    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"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 03-31-2009, 04:23 PM
  2. Replies: 46
    Last Post: 08-24-2007, 04:52 PM
  3. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
  4. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 06:59 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21