9 Loops
-
R and Python include
ifandforas looping operator - Note indenting is important in Python; R is flexible although indented code is easier to read
9.1 R: if loop
x = 20
if (x %% 2 == 0){
cat('The number ', x, ' is EVEN')
} else {
cat('The number ', x, ' is ODD')
}The number 20 is EVEN
9.2 Python: if loop
x = 20
if x % 2 == 0:
print('The number ', x, ' is EVEN')
else:
print('The number ', x, ' is ODD')The number 20 is EVEN