For loop and stop
temperatures=c(15,20,19,-5,18,20)
for(i in 1:length(temperatures)){
if(temperatures[i]<0){
cat("Error:Negative temperature detected:",temperatures[i],"at index",i,"\n")
break
}else{
cat("temperature at index",i,"is",temperatures[i],"degrees\n")
}
}
Comments
Post a Comment