added c++ tree loop