Help with IF statements

This is a discussion on Help with IF statements within the C++ Programming forums, part of the General Programming Boards category; Is it possible to use the IF statement over several lines? Because i have quite afew conditions that have to ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    59

    Help with IF statements

    Is it possible to use the IF statement over several lines?

    Because i have quite afew conditions that have to be met in order
    to continue my program.....

    And if i put them all in it stretches right across the screen.

    Thanks

    Boontune

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    More like:

    Code:
    if (  Condition
       || Condition
       || Condition )
    {
      /* Something here */
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    You can do this with anything, as long as there's no ';' it assumes
    the line is not finished yet and move's on to the next line.

    A big argument list for example.

    Code:
    void blab(int a,int b,int c,int d,int e,int i,int f,int g,int z,int x,
                    int r,int y);

  4. #4
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    You can also do this with a string (use the \ character to separate the string):
    Code:
    int main(void)
    {
       char a[] = "Hello " \
             "worl" \
             "d!";
    
       printf("%s\n", a);
       return 0;
    }

  5. #5
    Registered User
    Join Date
    Dec 2002
    Posts
    103

    Does this answer your question

    Code:
    // This can be done
    if(condition1)
    {
          statement1;
    }
    else if(condition2)
    {
          statement2;
    }
    else 
    {
          statement3;
    }
    
    // This also can be done
    if(condition1)
    {
          if(condition2)
          {
               if(condition3)
               {
                    statement1;
                    statement2;
                    ..................
                }
          }
    }
    Last edited by shiv_tech_quest; 01-22-2003 at 06:53 AM.
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    The way i understand it he has many conditions for his IF
    statement, therefore they don't all fit on 1 line, si he'd like
    to know if he could go on the next line with conditions.
    Answer is sure.

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    Thats right !

    But i think it was answered on the second post!

    Cheers guys!


    Just one more thing, whats the function called for checking punctuation?

  8. #8
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>whats the function called for checking punctuation?
    Care to expand your question a little?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #9
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #10
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    Yeah sorry,

    I mean in the header file ctype.h, there are functions you can use to check conditions, ie.

    isdigit() - to check numbers
    isalpha() - for letters

    I need to know what the one for punctuation is?

  11. #11
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    ... and in your crossposted thread, I told you to open your ctype.h file and look! You will find what you want, and a load of other stuff.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  12. #12
    Registered User
    Join Date
    Dec 2002
    Posts
    103
    Originally posted by boontune
    Yeah sorry,

    I mean in the header file ctype.h, there are functions you can use to check conditions, ie.

    isdigit() - to check numbers
    isalpha() - for letters

    I need to know what the one for punctuation is?
    You could code a function on your own if the one you are searching is not existing

    Code:
    bool ispunctuation(char ch)
    {
         return (ch == '\''); // since ' (quote / punctuation) has a special meaning, we need to use the a quote then a slash (backward) then a quote then another quote
    }
    Last edited by shiv_tech_quest; 01-22-2003 at 07:30 AM.
    Have a wonderful day.... and keep smiling... you look terrific that way
    signing off...
    shiv... as i know him

  13. #13
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    hehe sorry mate,

    I have just look in ctype.h

    Thanks alot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. C++ If Statements Help
    By moporho in forum C++ Programming
    Replies: 19
    Last Post: 01-18-2008, 07:40 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Need help with "if" statements
    By Harryt123 in forum C Programming
    Replies: 22
    Last Post: 05-14-2006, 08:18 AM

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