Your loop is just "overwriting" your variables each time.

And the last line of your loop 'ii=ii+1' means that,

KevenAnna Resistance Loop Bands - Fitness Exercise Bands Set of 4 - for Improving Mobility, Strength, Yoga Anywhere

Too low to display
  • Review
  • TAG : Hi, it's my first time to write a loop with R for my homework. This
ADD TO CART
  • You have two nested for loops in the code chunk above and thus two sets of curly braces, each with its own block and governed by its own index. That is, runs over the lines and runs over the columns.

    If the result is False (F), the loop is never executed as indicated by the loose arrow on the right of the figure. The program will then execute the first instruction it finds after the loop block.

  • If the result is False (F), the loop is never executed as indicated by the loose arrow on the right of the figure. The program will then execute the first instruction it finds after the loop block.

    As a start, we use a user defined function to get the user input before entering the loop. This loop will continue as long as the answer is not the expected .

    #!/bin/bash
    # The "continue N" command, continuing at the Nth level loop.
    
    for outer in I II III IV V           # outer loop
    do
      echo; echo -n "Group $outer: "
    
      # --------------------------------------------------------------------
      for inner in 1 2 3 4 5 6 7 8 9 10  # inner loop
      do
    
        if [[ "$inner" -eq 7 && "$outer" = "III" ]]
        then
          continue 2  # Continue at loop on 2nd level, that is "outer loop".
                      # Replace above line with a simple "continue"
                      # to see normal loop behavior.
        fi  
    
        echo -n "$inner "  # 7 8 9 10 will not echo on "Group III."
      done  
      # --------------------------------------------------------------------
    
    done
    
    echo; echo
    
    # Exercise:
    # Come up with a meaningful use for "continue N" in a script.
    
    exit 0

  • #!/bin/bash
    
    LIMIT=19  # Upper limit
    
    echo
    echo "Printing Numbers 1 through 20 (but not 3 and 11)."
    
    a=0
    
    while [ $a -le "$LIMIT" ]
    do
     a=$(($a+1))
    
     if [ "$a" -eq 3 ] || [ "$a" -eq 11 ]  # Excludes 3 and 11.
     then
       continue      # Skip rest of this particular loop iteration.
     fi
    
     echo -n "$a "   # This will not execute for 3 and 11.
    done 
    
    # Exercise:
    # Why does the loop print up to 20?
    
    echo; echo
    
    echo Printing Numbers 1 through 20, but something happens after 2.
    
    ##################################################################
    
    # Same loop, but substituting 'break' for 'continue'.
    
    a=0
    
    while [ "$a" -le "$LIMIT" ]
    do
     a=$(($a+1))
    
     if [ "$a" -gt 2 ]
     then
       break  # Skip entire rest of loop.
     fi
    
     echo -n "$a "
    done
    
    echo; echo; echo
    
    exit 0

    In other terms, aside from the “natural” end of the loop, which occurs either because you reached the prescribed number of iterations () or because you met a condition (, ), can you stop or interrupt the loop?

And the last line of your loop 'ii=ii+1' means that,

Underneath the R code you just executed is blazingly fast C code running loops to get you the answer. The upshot here is that C is much faster than R and if you can do get what you seek in R by applying a command to a vector it’s typically a good idea to do so.