Loops/Wrong ranges: Difference between revisions

Content added Content deleted
m (→‎{{header|Phix}}: corrected category)
m (→‎{{header|R}}: Syntax highlighting.)
Line 1,722: Line 1,722:
=={{header|R}}==
=={{header|R}}==
Aside from the second case, this behaviour is explained by two sentences of seq's documentation: "''generates '''from''', '''from'''+'''by''', ..., up to the sequence value less than or equal to '''to'''. Specifying '''to''' - '''from''' and '''by''' of opposite signs is an error.''" As we can see, '''from''' is always included whenever an error is not thrown and '''to''' will be missed if it cannot be reached.
Aside from the second case, this behaviour is explained by two sentences of seq's documentation: "''generates '''from''', '''from'''+'''by''', ..., up to the sequence value less than or equal to '''to'''. Specifying '''to''' - '''from''' and '''by''' of opposite signs is an error.''" As we can see, '''from''' is always included whenever an error is not thrown and '''to''' will be missed if it cannot be reached.
<lang r>seq(from = -2, to = 2, by = 1)#Output: -2 -1 0 1 2
<lang rsplus>seq(from = -2, to = 2, by = 1)#Output: -2 -1 0 1 2
seq(from = -2, to = 2, by = 0)#Fails: "invalid '(to - from)/by'"
seq(from = -2, to = 2, by = 0)#Fails: "invalid '(to - from)/by'"
seq(from = -2, to = 2, by = -1)#Fails: As in the notes above - "Specifying to - from and by of opposite signs is an error."
seq(from = -2, to = 2, by = -1)#Fails: As in the notes above - "Specifying to - from and by of opposite signs is an error."