Thread: Which code is more effective?

  1. #1
    Unregistered
    Guest

    Question Which code is more effective?

    Which cod is more effective?

    int main()
    {
    int err = 0;
    ...
    err = Function1();
    if( err != 0 ){
    ...
    return 1;
    }
    ...
    err = Function2();
    if( err != 0 ){
    ...
    return 2;
    }
    ...
    err = Function3();
    if( err != 0 ){
    ...
    return 3;
    }
    ...
    return 0;
    }

    OR:

    int main()
    {
    int err = 0;
    ...
    err = Function1();
    if( err == 0 ){
    ...
    err = Function2();
    if( err == 0 ){
    ...
    err = Function3();
    if( err == 0 ){
    ...
    }
    }
    }
    return err;
    }

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    a) this is the C# board

    b)

    >Which code is more effective?

    That depends on the situation. They both do the same, in the same amount of time. How you format it in the end is likely to be influenced by existing coding standards for your workplace or your own habits. Most effective is the version that is easier to read. But there is no perfect solution to this, as people are still arguing what is easier to read
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  4. Updated sound engine code
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 11-18-2004, 12:38 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM