[Vala] for loop and closure (bug or big gotcha?)
- From: Nor Jaidi Tuah <norjaidi tuah ubd edu bn>
- To: vala-list gnome org
- Subject: [Vala] for loop and closure (bug or big gotcha?)
- Date: Wed, 20 Jan 2010 14:00:28 +0800
Given this:
for (int i=0; i < 10; i++) {
button[i].clicked.connect ((s) => {stdout.printf ("%d\n", i);});
}
all the buttons, when clicked, outputs 10.
i.e., the variable i is treated as non-local and shared
by all those closures.
Is this the correct semantic?
If this is up for debate I would say that this is
a wrong semantic. Different iteration of the for loop
should use "different" i.
hand
Nor Jaidi Tuah
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]