Last change
on this file since db19e1d was
96de72b,
checked in by JiadaL <j82liang@…>, 3 months ago
|
- Update contribution; 2. update loop subsection; 3. rangeLoops.cfa are the code example used in loop section
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Line | |
---|
1 | #include <enum.hfa> |
---|
2 | #include <fstream.hfa> |
---|
3 | |
---|
4 | enum() Chars{A, B, C, D}; |
---|
5 | forall(E | CfaEnum(E) | Serial(E)) void baz(E) { |
---|
6 | for (e; E) { |
---|
7 | sout | label(e); |
---|
8 | } |
---|
9 | } |
---|
10 | |
---|
11 | void foo() { |
---|
12 | for (unsigned i = 0; i < countof(Chars); i++) { |
---|
13 | sout | label((Chars)fromInt(i)); |
---|
14 | } |
---|
15 | sout | nl; |
---|
16 | for (Chars e = lowerBound();; e = succ(e)) { |
---|
17 | sout | label(e); |
---|
18 | if (e == upperBound()) break; |
---|
19 | } |
---|
20 | sout | nl; |
---|
21 | for (Chars e; A ~ = D) { |
---|
22 | sout | label(e); |
---|
23 | } |
---|
24 | sout | nl; |
---|
25 | for (e; A ~ = D) { |
---|
26 | sout | label(e); |
---|
27 | } |
---|
28 | sout | nl; |
---|
29 | for (Chars e; A - ~ = D) { |
---|
30 | sout | label(e); |
---|
31 | } |
---|
32 | sout | nl; |
---|
33 | for (e; A - ~ = D ~2) { |
---|
34 | sout | label(e); |
---|
35 | } |
---|
36 | sout | nl; |
---|
37 | for (e; Chars) { |
---|
38 | sout | label(e); |
---|
39 | } |
---|
40 | sout | nl; |
---|
41 | baz(A); |
---|
42 | } |
---|
43 | |
---|
44 | void bar() { |
---|
45 | for (unsigned i = countof(Chars) - 1; i >= 0; i--) {} |
---|
46 | for (Chars e = lowerBound(); e <= upperBound(); e = succ(e)) {} |
---|
47 | for (Chars e = upperBound(); e >= lowerBound(); e = pred(e)) {} |
---|
48 | } |
---|
49 | |
---|
50 | int main() { foo(); } |
---|
Note: See
TracBrowser
for help on using the repository browser.