Mailinglist Archive: yast-devel (157 mails)

< Previous Next >
Re: [yast-devel] YCP return bug?
  • From: Lukas Ocilka <lukas.ocilka@xxxxxxx>
  • Date: Mon, 11 Jun 2007 20:56:22 +0200
  • Message-id: <466D9AD6.4080602@xxxxxxx>
Benji Weber wrote:
> Hi all,
...
> Therefore I would expect the following programme to print "One" "Two"
> "Three". However, it actually prints "One" "One" "Three".
> 
>     string Two()
>     {
>         string value = "One";
>         foreach(string str, ["Two"],
>         {
>             return str;
>         });
>         return value;
>     }

"return" in "foreach" means that the interpreter skips to another loop
of the "foreach", eventually finishes the "foreach" if it is the last one.

You might want to modify your code this way :)

--- cut ---
string Two() {
    string value = "One";
    foreach(string str, ["Two"], {
        value = str;
    });
    return value;
}

--- cut ---

http://forgeftp.novell.com/yast/doc/SL10.2/tdg/YCPBuiltinList_foreach.html

According to the link mentioned above, "return" in "foreach" should
return the last value value from "foreach".

--- cut ---
integer aaa_foreach = foreach (integer v, [1,2,3], { return v + 10; });
Then: aaa_foreach == 13
--- cut ---

Lukas
-- 
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups
References