Created
February 17, 2018 07:26
-
-
Save tats-u/98f7c9254a3b3a10bbf68d0aaa89ed5a to your computer and use it in GitHub Desktop.
Fizz Buzz (sh & Bash completion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Bash | |
for i in {1..100}; do # Don't have to use `seq` | |
# There are ((...))) and [[...]]] (didn't use this time) in Bash | |
if ((i % 15 == 0)); then | |
echo Fizz Buzz | |
elif ((i % 3 == 0)); then | |
echo Fizz | |
elif ((i % 5 == 0)); then | |
echo Buzz | |
else | |
echo $i | |
fi | |
done | |
# sh | |
for i in $(seq 100); do | |
if [ $(expr $i % 15) = 0 ]; then # Use `expr` to compute | |
echo Fizz Byuzz | |
elif [ $(expr $i % 3) = 0 ]; then | |
echo Fizz | |
elif [ $(expr $i % 5) = 0 ]; then | |
echo Buzz | |
else | |
echo $i | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment