import std.stdio;
class Foo
{
Foo parent;
int state;
this (int state) { this.state = state; }
}
void main()
{
auto foo = new Foo(0);
foo.parent = new Foo(1);
foo.parent.parent = new Foo(2);
while (true)
{
if (auto par = foo.parent)
{
writeln(par.state);
foo = par;
}
else
{
break;
}
}
}