Try to understand it by evaluating each piece from the inside out, and see if you can figure out what it's doing, and how to use it to answer your question. A loop is a control statement that allows multiple executions of a statement or a set of statements.
Loops come in the class of the most fundamental and strong programming concepts. If you do it the first way (checking as you go), then initialize a variable for counting, something like "num_far_away 1))". Loops in R Are Slow Dont use a loop when a vectorized alternative exists Dont grow objects (via c, cbind, etc) during the loop - R has to create a new. Loops in R (for, while, repeat) In R programming, we require a control structure to run a block of code multiple times. Within the body of the for-loop we are then creating an output called x1, which contains the index of our loop to the power of 2. One design decision is whether to analyze each sample mean as you go to see if it is more than 1 gram away from the population mean, or if you collect all the sample means first, then check to see how many are far away. In the following R code, we are specifying within the head of the for-loop that we want to run through a vector containing ten elements from the first element (i.e. When you nest two loops, the outer loop takes.
This seems like a beginner question, so I'll give some suggestions using basic programming techniques. The placing of one loop inside the body of another loop is called nesting.