Mailinglist Archive: yast-devel (77 mails)

< Previous Next >
[yast-devel] Is it allowed to modify one same list via foreach?
  • From: Johannes Meixner <jsmeix@xxxxxxx>
  • Date: Wed, 2 Dec 2009 14:22:06 +0100 (CET)
  • Message-id: <alpine.LNX.2.00.0912021359410.12115@xxxxxxxxxxxxxx>

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" ] ?


If the above is allowed, what about even more evil looking code:
--------------------------------------------------------------------
list < string > words = [ "Jane", "John", "Joe" ];
integer index = -1;
foreach( string word,
words,
{ index = index + 1;
if( "John" == word )
{ remove( words, index );
}
}
);
--------------------------------------------------------------------
Is in any case the result words == [ "Jane", "Joe" ] ?


If it is not allowed, how to copy a list?
Does
--------------------------------------------------------------------
list < string > words = [ "Jane", "John", "Joe" ];
list < string > copy = words;
--------------------------------------------------------------------
result two totally separated lists words and copy
or does copy contain only a reference which points to words
so that
--------------------------------------------------------------------
remove( copy, 1 );
--------------------------------------------------------------------
would actually result copy == words == [ "Jane", "Joe" ] ?


Kind Regards
Johannes Meixner
--
SUSE LINUX Products GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
AG Nuernberg, HRB 16746, GF: Markus Rex
--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups