Working with nested loops