Re: case and foreach
- Posted by Tommy Carlier <tommy.carlier at telenet.be> Mar 31, 2005
- 549 views
codepilot Gmail Account wrote: > Pros > I think foreach could be used to add some parallelism to euphoria and > simplify a few things that for loops and subscripting are used for. > Case would be good for simplifying if/elsif/else blocks to a more > manageable level and could also help in optimization. > > Cons > Does anyone have something against case or foreach(element in a > sequence) in euphoria? I also think foreach would be a great advantage. It doesn't only allow for cleaner code, but could also greatly enhance performance by optimization: compare these 2 equivalent pieces of code: 1: sequence s = ... object x for i = 1 to length(s) do x = s[i] ... end for 2: sequence s = ... foreach x in s do ... end foreach Using foreach, you can eliminate the index checking (1 <= i <= length(s)). One suggestion: you can perfectly use the 'for' keyword, instead of adding a new keyword 'foreach'. Example: for x in s do ... end for -- The Internet combines the excitement of typing with the reliability of anonymous hearsay. tommy online: http://users.telenet.be/tommycarlier tommy.blog: http://tommycarlier.blogspot.com