Skip to content
This repository
file 133 lines (116 sloc) 1.873 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
#! nqp

# check control structure 'if ... else'

say('1..14');

if 1 { say("ok 1 # on one line with else"); } else { say("not ok 1 # on one line with else")}

say("ok 2 # statements following if with else are okay");

if 1 {
    print("ok 3");
}
else {
    print("not ok 3");
}
say(" # multi-line if with else");

if 0 {
    print("not ok 4");
}
else {
    print("ok 4");
}
say(" # multi-line if, else branch");

if 0 {
}
else {
    print("ok 5");
}
say(" # empty if-block");

if 0 {
    print("not ok 6");
}
else {
}
print("ok 6");
say(" # empty else-block");

if 0 {
}
else {
}
print("ok 7");
say(" # empty if- and else-block");

if 0 {
}
elsif 0 {
}
elsif 0 {
}
else {
}
print("ok 8");
say(" # empty if-, elsif-, and else-block");

if 1 {
    print("ok 9");
}
elsif 0 {
    print("not ok 9 # elsif 1");
}
elsif 0 {
    print("not ok 9 # elsif 2");
}
else {
    print("not ok 9 # else");
}
say(" # if expr true in if/elsif/elsif/else");

if 0 {
    print("not ok 10 # if");
}
elsif 1 {
    print("ok 10");
}
elsif 0 {
    print("not ok 10 # elsif 2");
}
else {
    print("not ok 10 # else");
}
say(" # first elsif expr true in if/elsif/elsif/else");

if 0 {
    print("not ok 11 # if");
}
elsif 0 {
    print("not ok 11 # elsif 1");
}
elsif 1 {
    print("ok 11");
}
else {
    print("not ok 11 # else");
}
say(" # second elsif expr true in if/elsif/elsif/else");

if 0 {
    print("not ok 12 # if");
}
elsif 1 {
    print("ok 12");
}
elsif 1 {
    print("not ok 12 # elsif 2");
}
else {
    print("not ok 12 # else");
}
say(" # first and second elsif expr true in if/elsif/elsif/else");

if 0 {
    print("not ok 13 # if");
}
elsif 0 {
    print("not ok 13 # elsif 1");
}
elsif 0 {
    print("not ok 13 # elsif 2");
}
else {
    print("ok 13");
}
say(" # else expr true in if/elsif/elsif/else");

if 0 { } elsif 0 { }
print("ok 14");
say(" # no else block in if/elsif")
Something went wrong with that request. Please try again.