Skip to content

Conditional Execution Error

1 message · Steve Murray

#
Dear all,


Please could someone explain why 'Version 1' of the code below works, but 'Version 2' produces an error (albeit following the correct output)?


#Version 1

h <- 10
j <- -5

if(h < j) {
print("statement is true")
} else {
while (h >= j) {
print(h)
h <- h - 1
}
}


#Version 2

h <- 10
j <- -5

ifelse(h < j, "statement is true", while(h >= j) {
print(h)
h <- h - 1
}
)



If anyone has an explanation and solution (for avoiding the error), then I'd be pleased to hear it.


Many thanks,

Steve