1. Useless code...
- Posted by "Carl W." <euphoria at cyreksoft.yorks.com> Nov 29, 2002
- 441 views
I don't know whether it happens to anyone else, but sometimes I get a mad algorithmic notion in my head that just has to be coded. Last night on the way home from work, I came up with 'nfor' - the ability to start any number of nested for-loops at the same time. A bit like coding: -- [fig.1]: for i = 1 to 10 do for j = 3 to 21 by 3 do for k = 3 to 17 by 7 do -- some code end for end for end for While the new library is virtually useless (and there are many things that can't be done with it), the above syntax ends up looking like this: -- [fig.2]: nfor({ {1,10}, {3,21,3}, {3,17,7} }) while 1 do -- some code if end_nfor() then exit end if end while -- The 'while' is used as the looping mechanism because Euphoria subroutines -- don't lend themselves easily to that sort of thing. :) To add another 'for' level to fig.1 requires adding code to the first line keeping all the loop values spread in difficult to read groups, and then adding another 'end for' to the end of the code. In fig.2 all that is needed is another tuple/triple in the nfor() params. If anyone is interested, the code and some notes are viewable via: http://www.cyreksoft.yorks.com/euphoria/ To reiterate - it /was/ based on a strange notion. :) Comments invited. Carl