* Johannes Meixner <[email protected]> [Dec 02. 2009 15:10]: > > Hello, > > On Dec 2 14:36 Arvin Schnell wrote (shortened): > >On Wed, Dec 02, 2009 at 02:22:06PM +0100, Johannes Meixner wrote: > >> > >>Hello, > >> > >>is such code allowed: > >>-------------------------------------------------------------------- > >>list < string > words = [ "Jane", "John" ]; > >>integer index = -1; > >>foreach( string word, > >> words, > >> { index = index + 1; > >> words[index] = "Hello " + word; > >> } > >> ); > >>-------------------------------------------------------------------- > >>Is in any case the result words == [ "Hello Jane", "Hello John" ] ? > > > >Use maplist: > > > > words = maplist(string word, words, { return "Hello " + word; }); > > Regardless of maplist/mapmap: > Is my above code using foreach allowed?
Yes, iterating over list and changing elements is fine. Changing the list size (adding, removing elements) should also be fine since the index limit is checked against the actual size on every iteration. (Information from top of my head, YMMV !) Klaus --- SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nürnberg) -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
