Is it possible to nest multiple if statements together within a while loop?
I'm attempting to create a simple example just to expose myself to them:
i <- 1
while(i <=10) {
if(i > 6){
cat("i=",i,"and is bigger than 6.\n")
}else{if(3<i & i<6){
cat("i=",i,"and is between 3 and 6.\n")
}else{
cat("i=",i,"and is 3 or less.\n")
}
i<-i+1
cat("At the bottom of the loop i is now =",i,"\n")
}
My sample code keeps getting stuck at i=7 and wants to run forever. How can I avoid this?
Aucun commentaire:
Enregistrer un commentaire