Conditional structures: Difference between revisions

m
m (→‎{{header|R}}: Syntax highlighting.)
Line 5,783:
===if===
Like most languages, R has an if statement as well as if-then-else:
<lang rrsplus>x<-0
if(x==0) print("foo")
x<-1
Line 5,794:
> if(x==0) print("foo") else print("bar")
[1] "bar"</pre>
 
===switch===
R also has switch, but it's a function rather than a special form of any sort. In fact, R has two versions of switch: one for numbers and one for characters.
331

edits