How to resolve the algorithm Loops/Continue step by step in the UNIX Shell programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Loops/Continue step by step in the UNIX Shell programming language

Table of Contents

Problem Statement

Show the following output using one loop.

Try to achieve the result by forcing the next iteration within the loop upon a specific condition, if your language allows it.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Loops/Continue step by step in the UNIX Shell programming language

Source code in the unix programming language

Z=1
while (( Z<=10 )); do
    echo -e "$Z\c"
    if (( Z % 5 != 0 )); then
        echo -e ", \c"
    else
        echo -e ""
    fi
    (( Z++ ))
done

for ((i=1;i<=10;i++)); do
  echo -n $i
  if [ $((i%5)) -eq 0 ]; then
    echo
    continue
  fi
  echo -n ", "
done

  

You may also check:How to resolve the algorithm Chaocipher step by step in the V (Vlang) programming language
You may also check:How to resolve the algorithm Sorting algorithms/Quicksort step by step in the UnixPipes programming language
You may also check:How to resolve the algorithm Sequence of primes by trial division step by step in the C programming language
You may also check:How to resolve the algorithm Loops/N plus one half step by step in the AutoIt programming language
You may also check:How to resolve the algorithm Loops/Infinite step by step in the Perl programming language