UMBC CMSC 104 CSEE | 104 | current 104

C Programming - Indentation Styles

Choose one of the two styles and use it consistently

    if (condition)                  if (condition) {
    {                                   statement(s)
        statement(s)                }
    }


    if (condition)                  if (condition) {
    {                                   statement(s)
        statement(s)                } else if (condition) {
    }                                   statement(s)
    else if (condition)             } else {
    {                                   statement(s)
        statement(s)                }
    }
    else
    {
        statement(s)
    }


    for (loop control expressions)   for (loop control expressions) {
    {                                    statement(s)
        statement(s)                 }
    }


    while (condition)                while (condition) {
    {                                    statement(s)
        statement(s)                 }
    }


    do                               do {
    {                                     statement(s)
        statement(s)                 } while (condition);
    } while (condition);


    switch (integer expression)        switch (integer expression) {
    {                                      case constant1:
        case constant1:                        statement(s)
            statement(s)                   case constant2:
        case constant2:                        statement(s)
            statement(s)                   default:
        default:                               statement(s)
            statement(s)               }
    }



Last Modified: Tuesday, 29-Aug-2006 05:56:41 EDT