using foreach instead of for