Moin, i just pushed two little patches to [0] which allows to add an else statement to foreach and catch statements. For foreach, the else block is called if there is no iteration in the loop. For the catch clause, the else block is called if no exception was caught and before the finally statement. Here are 2 little examples: foreach: void print_array (string[] args) { foreach (var arg in args) { debug(@"arg: $arg"); } else { debug("no args"); //called if the array is empty } } void main (string[] args) { string[] test_1 = new string[0]; string[] test_2 = new string[2]{"hello", "world"}; print_array (test_1); print_array (test_2); } catch: public errordomain TestError { FOO, } public void throw_error (bool t) throws TestError { if (t) { throw new TestError.FOO("foo"); } } void test(bool t) { try { throw_error (t); } catch (TestError e) { debug("error :("); } else { debug("success :)"); } finally { debug("finally"); } } void main(){ debug("false:"); test(false); debug("true:"); test(true); } ATM datatype using iterators don't work, but if you like the feature, I'll implement it. Same for "for...else". Regards, Frederik P.S.: There's a another branch, which supports async delegates/lambdas at [1] which requires some testing/reviewing. [0]: http://git.freesmartphone.org/?p=vala.git;a=shortlog;h=refs/heads/else-statements [1]: http://git.freesmartphone.org/?p=vala.git;a=shortlog;h=refs/heads/async -- IRC: playya @ Freenode, Gimpnet xmpp: playya draugr de identi.ca: playya
Attachment:
signature.asc
Description: Digital signature