R language: how to write for loop similar to java? -
i'm used writing for
loops in java using:
for (ii=10; ii<length(myarray); ii++) { }
if length(my array)
less 10, loop not execute. how in r language?
if try in r language:
for (ii in 10:length(myarray)) { }
the loop execute if length(myarray)
less 10, example. how write loop not execute in case?
use if
.
if (length(myarray) >= 10) { (ii in 10:length(myarray)) {...} }
if clear, can use while
try make r more java-like
ii = 10 while (ii < length(myarray)) { ... ii = ii + 1 }
but i've never seen r programmer this. does, say, replace if
, for
single while
, adds need initialize ii
, increment inside loop.
Comments
Post a Comment