2.41. Conditional Statements
Felix supports a traditional procedural if chain.
Here is a simple if/do/done:
Start felix section to tut/tutorial/tut-1.41-0.flx[1
/1
]
1: #line 4136 "./lpsrc/flx_tutorial.pak"
2:
3:
4:
5: proc f(x:int) {
6: if x == 1 do print "ONE"; endl; done;
7: }
8:
9: f 1;
10: f 2;
Start data section to tut/tutorial/tut-1.41-0.expect[1
/1
]
You can also have an else clause:
Start felix section to tut/tutorial/tut-1.41-1.flx[1
/1
]
1: #line 4154 "./lpsrc/flx_tutorial.pak"
2:
3:
4:
5: proc f(x:int) {
6: if x == 1 do print "ONE"; endl;
7: else print "Not a one .."; endl;
8: done;
9: }
10:
11: f 1;
12: f 2;
Start data section to tut/tutorial/tut-1.41-1.expect[1
/1
]
and even elif clauses:
Start felix section to tut/tutorial/tut-1.41-2.flx[1
/1
]
1: #line 4175 "./lpsrc/flx_tutorial.pak"
2:
3:
4:
5: proc f(x:int) {
6: if x == 1 do print "ONE"; endl;
7: elif x == 2 do print "TWO"; endl;
8: else print "Not a one .."; endl;
9: done;
10: }
11:
12: f 1;
13: f 2;
14: f 3;
Start data section to tut/tutorial/tut-1.41-2.expect[1
/1
]
1: ONE
2: TWO
3: Not a one ..
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/tutorial/tut-1.41-3.flx[1
/1
]
1: #line 4201 "./lpsrc/flx_tutorial.pak"
2:
3:
4:
5: proc f(x:int) {
6: if x == 1 do print "ONE "; endl;
7: elif x == 2 return;
8: else print "Weird ";
9: done;
10: print "Found";
11: }
12:
13: f 1;
14: f 2;
15: f 3;
16: endl;
Start data section to tut/tutorial/tut-1.41-3.expect[1
/1
]
1: ONE
2: FoundWeird Found