an alternative to nested "for" loops