1.40. Conditional Statements
Felix supports a traditional procedural if chain.
Here is a simple if/do/done:
Start felix section to tut/examples/tut_beg149a.flx[1
/1
]
1: #line 2176 "./lpsrc/flx_tutorial.pak"
2:
3:
4: proc f(x:int) {
5: if x == 1 do print "ONE"; endl; done;
6: }
7:
8: f 1;
9: f 2;
10:
You can also have an else clause:
Start felix section to tut/examples/tut_beg149b.flx[1
/1
]
1: #line 2189 "./lpsrc/flx_tutorial.pak"
2:
3:
4: proc f(x:int) {
5: if x == 1 do print "ONE"; endl;
6: else print "Not a one .."; endl;
7: done;
8: }
9:
10: f 1;
11: f 2;
12:
and even elif clauses:
Start felix section to tut/examples/tut_beg149c.flx[1
/1
]
1: #line 2204 "./lpsrc/flx_tutorial.pak"
2:
3:
4: proc f(x:int) {
5: if x == 1 do print "ONE"; endl;
6: elif x == 2 do print "TWO"; endl;
7: else print "Not a one .."; endl;
8: done;
9: }
10:
11: f 1;
12: f 2;
13: f 3;
14:
Any number of statements can be used, including none.
You can also use a conditional return or goto instead
of the do part:
Start felix section to tut/examples/tut_beg149d.flx[1
/1
]
1: #line 2223 "./lpsrc/flx_tutorial.pak"
2:
3:
4: proc f(x:int) {
5: if x == 1 do print "ONE "; endl;
6: elif x == 2 return;
7: else print "Weird ";
8: done;
9: print "Found";
10: }
11:
12: f 1;
13: f 2;
14: f 3;
15: endl;
16: