dimanche 16 décembre 2018

skipping iterations in R loops

ive been asked to program a game that prints "boom" each time a number is either divisible by 7, or contains 7, for seq(1:31) . so far so good:

num_turns=c(1:31)
for(i in seq(1,31)){
  if(i%%7==0 || "7" %in% i){
    print("boom")
  }else{
    print(i)
  }
}

then im asked to repeat the game for seq(1:55), but with conditions: there are 4 players, im player #3, and to only print my turns. these are the variables i was asked to create:

total_players=4
player_num=3
turns=55

any advise on how to code this?

Aucun commentaire:

Enregistrer un commentaire