[f6737ae1] | 1 | #include <fstream.hfa> |
---|
| 2 | |
---|
| 3 | struct S { int i, j; }; |
---|
| 4 | void ?{}( S & s ) { s.[i, j] = 0; } |
---|
| 5 | void ?{}( S & s, int i ) { s.[i, j] = [i, 0]; } |
---|
| 6 | void ?{}( S & s, int i, int j ) { s.[i, j] = [i, j]; } |
---|
| 7 | void ?{}( S & s, zero_t ) { s.[i, j] = 0; } |
---|
| 8 | void ?{}( S & s, one_t ) { s.[i, j] = 1; } |
---|
| 9 | int ?<?( S t1, S t2 ) { return t1.i < t2.i && t1.j < t2.j; } |
---|
| 10 | int ?<=?( S t1, S t2 ) { return t1.i <= t2.i && t1.j <= t2.j; } |
---|
| 11 | int ?>?( S t1, S t2 ) { return t1.i > t2.i && t1.j > t2.j; } |
---|
| 12 | int ?>=?( S t1, S t2 ) { return t1.i >= t2.i && t1.j >= t2.j; } |
---|
| 13 | S ?=?( S & t1, S t2 ) { t1.i = t2.i; t1.j = t2.j; return t1; } |
---|
| 14 | S ?+=?( S & t1, S t2 ) { t1.i += t2.i; t1.j += t2.j; return t1; } |
---|
| 15 | S ?+=?( S & t, one_t ) { t.i += 1; t.j += 1; return t; } |
---|
| 16 | S ?-=?( S & t1, S t2 ) { t1.i -= t2.i; t1.j -= t2.j; return t1; } |
---|
| 17 | S ?-=?( S & t, one_t ) { t.i -= 1; t.j -= 1; return t; } |
---|
| 18 | ofstream & ?|?( ofstream & os, S v ) { return os | '(' | v.i | v.j | ')'; } |
---|
| 19 | void & ?|?( ofstream & os, S v ) { (ofstream &)(os | v); ends( os ); } |
---|
| 20 | |
---|
| 21 | int main() { |
---|
[c48b61c] | 22 | // Test some loop options. |
---|
[f6737ae1] | 23 | |
---|
[c48b61c] | 24 | sout | nlOff; // turn off auto newline |
---|
| 25 | while () { sout | "empty"; break; } else { sout | "else"; } sout | nl; |
---|
| 26 | do { sout | "empty"; break; } while () else { sout | "else"; } sout | nl; |
---|
| 27 | for () { sout | "empty"; break; } else { sout | "else"; } sout | nl | nl; |
---|
[f6737ae1] | 28 | |
---|
[c48b61c] | 29 | do { sout | "false"; } while (false) else { sout | "else"; } sout | nl | nl; |
---|
| 30 | |
---|
| 31 | for ( 0 ) { sout | "A"; } else { sout | "else"; } sout | "zero" | nl; |
---|
[f6737ae1] | 32 | for ( 1 ) { sout | "A"; } else { sout | "else"; } sout | nl; |
---|
[c48b61c] | 33 | for ( 10 ) { sout | "A"; } else { sout | "else"; } sout | nl; |
---|
[5c98a25] | 34 | for ( ~= 10 ) { sout | "A"; } else { sout | "else"; } sout | nl; |
---|
[f6737ae1] | 35 | for ( 1 ~= 10 ~ 2 ) { sout | "B"; } else { sout | "else"; } sout | nl; |
---|
[c48b61c] | 36 | for ( 1 -~= 10 ~ 2 ) { sout | "C"; } else { sout | "else"; } sout | nl; |
---|
[f6737ae1] | 37 | for ( 0.5 ~ 5.5 ) { sout | "D"; } else { sout | "else"; } sout | nl; |
---|
[c48b61c] | 38 | for ( 0.5 -~ 5.5 ) { sout | "E"; } else { sout | "else"; } sout | nl | nl; |
---|
[f6737ae1] | 39 | |
---|
| 40 | for ( i; 10 ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[5c98a25] | 41 | for ( i; ~= 10 ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[f6737ae1] | 42 | for ( i; 1 ~= 10 ~ 2 ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[c48b61c] | 43 | for ( i; 1 -~= 10 ~ 2 ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[f6737ae1] | 44 | for ( i; 0.5 ~ 5.5 ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[c48b61c] | 45 | for ( i; 0.5 -~ 5.5 ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[f6737ae1] | 46 | for ( ui; 2u ~= 10u ~ 2u ) { sout | ui; } else { sout | "else"; } sout | nl; |
---|
[c48b61c] | 47 | for ( ui; 2u -~= 10u ~ 2u ) { sout | ui; } else { sout | "else"; } sout | nl | nl; |
---|
[f6737ae1] | 48 | |
---|
| 49 | // @ means do nothing |
---|
| 50 | for ( i; 1 ~ @ ) { |
---|
| 51 | if ( i > 10 ) break; |
---|
| 52 | sout | i; |
---|
| 53 | } else { sout | "else"; } sout | nl; |
---|
[283876d] | 54 | for ( i; @ -~ 10 ) { |
---|
[f6737ae1] | 55 | if ( i < 0 ) break; |
---|
| 56 | sout | i; |
---|
| 57 | } else { sout | "else"; } sout | nl; |
---|
| 58 | for ( i; 2 ~ @ ~ 2 ) { |
---|
| 59 | if ( i > 10 ) break; |
---|
| 60 | sout | i; |
---|
| 61 | } else { sout | "else"; } sout | nl; |
---|
| 62 | for ( i; 2.1 ~ @ ~ @ ) { |
---|
| 63 | if ( i > 10.5 ) break; |
---|
| 64 | sout | i; |
---|
| 65 | i += 1.7; |
---|
| 66 | } else { sout | "else"; } sout | nl; |
---|
[283876d] | 67 | for ( i; @ -~ 10 ~ 2 ) { |
---|
[f6737ae1] | 68 | if ( i < 0 ) break; |
---|
| 69 | sout | i; |
---|
| 70 | } else { sout | "else"; } sout | nl; |
---|
| 71 | for ( i; 12.1 ~ @ ~ @ ) { |
---|
| 72 | if ( i < 2.5 ) break; |
---|
| 73 | sout | i; |
---|
| 74 | i -= 1.7; |
---|
| 75 | } else { sout | "else"; } sout | nl | nl; |
---|
| 76 | |
---|
| 77 | enum { N = 10 }; |
---|
| 78 | for ( N ) { sout | "N"; } else { sout | "else"; } sout | nl; |
---|
| 79 | for ( i; N ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[5c98a25] | 80 | for ( i; ~= N ) { sout | i; } else { sout | "else"; } sout | nl; |
---|
[c48b61c] | 81 | for ( i; -~= N ) { sout | i; } else { sout | "else"; } sout | nl | nl; |
---|
[f6737ae1] | 82 | |
---|
| 83 | const int start = 3, comp = 10, inc = 2; |
---|
| 84 | for ( i; start ~ comp ~ inc + 1 ) { sout | i; } else { sout | "else"; } sout | nl | nl; |
---|
| 85 | |
---|
[283876d] | 86 | for ( i; 10 : j; -5 ~ @ ) { sout | i | j; } else { sout | "else"; } sout | nl; |
---|
| 87 | for ( i; 10 : j; @ -~ -5 ) { sout | i | j; } else { sout | "else"; } sout | nl; |
---|
| 88 | for ( i; 10 : j; -5 ~ @ ~ 2 ) { sout | i | j; } else { sout | "else"; } sout | nl; |
---|
| 89 | for ( i; 10 : j; @ -~ -5 ~ 2 ) { sout | i | j; } else { sout | "else"; } sout | nl | nl; |
---|
| 90 | |
---|
| 91 | for ( j; -5 ~ @ : i; 10 ) { sout | i | j; } else { sout | "else"; } sout | nl; |
---|
| 92 | for ( j; @ -~ -5 : i; 10 ) { sout | i | j; } else { sout | "else"; } sout | nl; |
---|
| 93 | for ( j; -5 ~ @ ~ 2 : i; 10 ) { sout | i | j; } else { sout | "else"; } sout | nl; |
---|
| 94 | for ( j; @ -~ -5 ~ 2 : i; 10 ) { sout | i | j; } else { sout | "else"; } sout | nl | nl; |
---|
| 95 | |
---|
| 96 | for ( j; @ -~ -5 ~ 2 : i; 10 : k; 1.5 ~ @ ) { sout | i | j | k; } else { sout | "else"; } sout | nl; |
---|
| 97 | for ( j; @ -~ -5 ~ 2 : k; 1.5 ~ @ : i; 10 ) { sout | i | j | k; } else { sout | "else"; } sout | nl; |
---|
| 98 | for ( k; 1.5 ~ @ : j; @ -~ -5 ~ 2 : i; 10 ) { sout | i | j | k; } else { sout | "else"; } sout | nl; |
---|
| 99 | |
---|
[f6737ae1] | 100 | for ( S s = (S){0}; s < (S){10,10}; s += (S){1} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 101 | for ( s; (S){10,10} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 102 | sout | nl; |
---|
| 103 | for ( s; (S){0} ~ (S){10,10} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 104 | for ( s; (S){0} ~ (S){10,10} ~ (S){1} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 105 | for ( s; (S){0} ~= (S){10,10} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 106 | for ( s; (S){0} ~= (S){10,10} ~ (S){1} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 107 | sout | nl; |
---|
[c48b61c] | 108 | for ( s; (S){0} -~ (S){10,10} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 109 | for ( s; (S){0} -~ (S){10,10} ~ (S){1} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 110 | for ( s; (S){0} -~= (S){10,10} ) { sout | s; } else { sout | "else"; } sout | nl; |
---|
| 111 | for ( s; (S){0} -~= (S){10,10} ~ (S){1} ) { sout | s; } else { sout | "else"; } sout | nl | nl; |
---|
[5c98a25] | 112 | } |
---|