Java code to follow wiki loops