wurmlab / SBC361-programming-in-R

QMUL's programming in R course
https://wurmlab.github.io/SBC361-programming-in-R/practical1.html
5 stars 11 forks source link

practical 2: need feedback on nested loop example #26

Open EmelineFavreau opened 7 years ago

EmelineFavreau commented 7 years ago

It is an example in Nested loop paragraph:

coffee_drinks <- c("latte", "cappuccino", "espresso", "flat white", "cortado")
coffee_places <- c("Infusion", "Ground", "Sugar Cube", "Foxcroft & Ginger", "Sweet")

for (the_drink in 1:length(coffee_drinks)) {
  for (the_place in 1:length(coffee_places)) {
    print(paste("I'd like a", coffee_drinks[the_drink], "from", coffee_places[the_place]))
  }
}

Does it represent what we wanted?

yannickwurm commented 7 years ago

Don't cycle through the positions. Just cycle through the items.

Typos courtesy of my iPhone

On 17 Oct 2017, at 20:18, Emeline Favreau notifications@github.com<mailto:notifications@github.com> wrote:

It is an example in Nested loop paragraph:

coffee_drinks <- c("latte", "cappuccino", "espresso", "flat white", "cortado") coffee_places <- c("Infusion", "Ground", "Sugar Cube", "Foxcroft & Ginger", "Sweet")

for (the_drink in 1:length(coffee_drinks)) { for (the_place in 1:length(coffee_places)) { print(paste("I'd like a", coffee_drinks[the_drink], "from", coffee_places[the_place])) } }

Does it represent what we wanted?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/wurmlab/SBC361-programming-in-R/issues/26, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAJKYT5qSiNuTIyqX5QzfjwjH8tceoDAks5stP1tgaJpZM4P8rqo.