foreach instead of while