To create a loop in bash, you can use the for
or while
loop construct.
Here is an example of a for
loop in bash that iterates over a range of numbers and echoes each number:
35 chars5 lines
And here is an example of a while
loop that iterates until a certain condition is met (in this case, until a counter variable reaches a certain value):
85 chars7 lines
In R, you can use a variety of loop constructs, including for
loops, while
loops, and repeat
loops.
Here is an example of a for
loop in R that iterates over a vector and prints each element:
66 chars5 lines
And here is an example of a while
loop in R that iterates until a certain condition is met (in this case, until a counter variable reaches a certain value):
80 chars6 lines
You can also use other constructs such as repeat
loop or apply functions like lapply
and sapply
in R.
gistlibby LogSnag