// -------------
// Selection.c++
// -------------

#include <cassert>  // assert
#include <iostream> // cout, endl

int f (int i, int j) {
    int k;
    if (i == -1) {
        if (j == -1)
            k = 1;
        else
            k = 2;}
    else if (j == -1)
        k = 3;
    else
        k = 4;
    return k;}

int g (int i, int j) {
    return (i == -1) ? ((j == -1) ? 1 : 2) : ((j == -1) ? 3 : 4);}

int h (int i, int j) {
    int k;
    switch (i) {
        case -1:
            switch (j) {
                case -1:
                    k = 1;
                    break;
                default:
                    k = 2;
                    break;}
            break;
        default:
            switch (j) {
                case -1:
                    k = 3;
                    break;
                default:
                    k = 4;
                    break;}
            break;}
    return k;}

int main () {
    using namespace std;
    cout << "Selection.c++" << endl;

    assert(f(-1, -1) == 1);
    assert(f(-1,  1) == 2);
    assert(f( 1, -1) == 3);
    assert(f( 1,  1) == 4);

    assert(g(-1, -1) == 1);
    assert(g(-1,  1) == 2);
    assert(g( 1, -1) == 3);
    assert(g( 1,  1) == 4);

    assert(h(-1, -1) == 1);
    assert(h(-1,  1) == 2);
    assert(h( 1, -1) == 3);
    assert(h( 1,  1) == 4);

    {
    int s = 0;
    if (int i = 2)
        s = i;
    else
        s = i + 1;
//  assert(i == 2);                     // error: 'i' was not declared in this scope
    assert(s == 2);
    }

    {
    int i = 2;
    const int s = (i == 2) ? i : i + 1;
    assert(i == 2);
    assert(s == 2);
    }

    {
    int s = 0;
    switch (int i = 2) {
        case 0:
            s = i + 1;
            break;
        default:
            s = i;
            break;}
//  assert(i == 2);                     // error: 'i' was not declared in this scope
    assert(s == 2);
    }

    cout << "Done." << endl;
    return 0;}


syntax highlighted by Code2HTML, v. 0.9.1