Programmierrichtlinien für C - 5


< Zurück | Vorwärts | Inhalt >
(DI Wittner Michael)

Anweisungen

  • if - Anweisung
  • for-, while-, do-while Anweisung
  • switch-Anweisung
  • Die Länge eines Blockes innerhalb einer Anweisung darf auf Grund der Übersichtlichkeit eine Bildschirmseite nicht überschreiten. Im folgenden werden wieder beide Klammerungsmöglichkeiten angeführt. Beachte, daß in einem Programm einheitlich Version A oder B verwendet werden muß.
    if (condition) {
      statements;
    }

    if (condition) {
      statements;
    } else {
      statements;
    }

    if (condition) {
      statements;
    } else if (condition) {
      statements;
    } else if (condition) {
      statements;
    }

    if (condition)
    {
      statements;
    }

    if (condition)
    {
      statements;
    }
    else
    {
      statements;
    }

    if (condition)
    {
      statements;
    }
    else if (condition)
    {
      statements;
    }
    else if (condition)
    {
      statements;
    }

    Die Laufvariable in for-Anweisungen darf im Schleifenrumpf nicht verändert werden!!
    for (initialization; condition; update) {
      statements;
    }

    while (condition) {
      statements;
    }

    do {
      statements;
    } while (condition);

    for (init; cond; update)
    {
      statements;
    }

    while (condition)
    {
      statements;
    }

    do
    {
      statements;
    } while (condition);

    switch (event) {
      case ABC:
        statements;
        break;
      case DEF:
        statements;
        break;
      default:
        break;
    }
    switch (event)
    {
      case ABC:
        statements;
        break;
      case DEF:
        statements;
        break;
      default:
        break;
    }
    Anmerkung: würde in einem Block ({}) innerhalb einer Anweisung nur eine Zeile stehen, so darf die Blockklammerung weggelassen werden. Eingerückt wird trotzdem!

    < Zurück | Vorwärts | Inhalt >