loop using scala way