Looping and Skipping

  • + 0 comments

    Three solutions; the last one is the " real" solution since it is checking for odd numbers according to the problem instructions.

    # Solution (1)
    #for n in {1..99..2} # start at 1, count up to 99 by incrementing by 2
    #do
    #    echo $n
    #done
    #    
    # Solution (2)      # same here
    #for (( n = 1; n <= 99; n += 2 ))
    #do
    #    echo $n
    #done
    #
    # Solution (3)      # by checking for odd numbers
    for n in {1..99}
    do
        if (( $n%2 != 0 ))
        then
            echo $n
        fi
    done