Thread: Proper form for Simple Conditional statements?

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    93

    Proper form for Simple Conditional statements?

    What's the scoop on simple conditional statements like shown below...Should you use #1 or #2?

    Code:
    #1
    if (blah != 0)
        tnt = yyz;
    else
        tnt = 0;
    
    #2
    if (blah != 0)
    {
        tnt = yyz;
    }
    else
    {
        tnt = 0;
    }
    If #1 is acceptable practice; can it still be used in nested conditional statements?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by TAZIN View Post
    What's the scoop on simple conditional statements like shown below...Should you use #1 or #2?
    Yes. (The general preference would probably be #2, as then adding a line can't get you into trouble for getting the braces. Also a lot of editors can add braces for you anyway.)
    Quote Originally Posted by TAZIN View Post
    If #1 is acceptable practice; can it still be used in nested conditional statements?
    Of course.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conditional Statements
    By strokebow in forum C Programming
    Replies: 30
    Last Post: 11-22-2006, 06:08 PM
  2. problem with floats in conditional statements
    By Desolation in forum C Programming
    Replies: 3
    Last Post: 07-08-2006, 01:56 AM
  3. multi conditional if statements?
    By chaser in forum Game Programming
    Replies: 3
    Last Post: 07-26-2002, 10:52 PM
  4. Using floats in conditional statements
    By DBB in forum C++ Programming
    Replies: 3
    Last Post: 09-12-2001, 07:54 AM