Conditional structures: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) m (→{{header|R}}: Syntax highlighting.) |
ReeceGoding (talk | contribs) m (→if) |
||
Line 5,783: | Line 5,783: | ||
===if=== |
===if=== |
||
Like most languages, R has an if statement as well as if-then-else: |
Like most languages, R has an if statement as well as if-then-else: |
||
<lang |
<lang rsplus>x<-0 |
||
if(x==0) print("foo") |
if(x==0) print("foo") |
||
x<-1 |
x<-1 |
||
Line 5,794: | Line 5,794: | ||
> if(x==0) print("foo") else print("bar") |
> if(x==0) print("foo") else print("bar") |
||
[1] "bar"</pre> |
[1] "bar"</pre> |
||
===switch=== |
===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. |
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. |