Created
November 2, 2013 16:38
-
-
Save GingerGeek/7280848 to your computer and use it in GitHub Desktop.
I have a logical problem to do with for loops calling another instance of themselves. I am using Bash
This file contains 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
0 <-- Dollar One | |
5 <-- Dollar Two | |
i is equal to: 0 | |
i is equal to: 1 | |
i is equal to: 2 | |
i is equal to: 3 | |
I am about to execute ForLoop. i is 3 | |
6 <-- Dollar One | |
10 <-- Dollar Two | |
i is equal to: 6 | |
i is equal to: 7 | |
i is equal to: 8 | |
i is equal to: 9 | |
i is equal to: 10 | |
ForLoop has been executed. i is 3 | |
i is equal to: 4 | |
i is equal to: 5 |
This file contains 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
0 <-- Dollar One | |
5 <-- Dollar Two | |
i is equal to: 0 | |
i is equal to: 1 | |
i is equal to: 2 | |
i is equal to: 3 | |
I am about to execute ForLoop. i is 3 | |
6 <-- Dollar One | |
10 <-- Dollar Two | |
i is equal to: 6 | |
i is equal to: 7 | |
i is equal to: 8 | |
i is equal to: 9 | |
i is equal to: 10 | |
ForLoop has been executed. i is 11 |
This file contains 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
ForLoop () { | |
echo "$1 <-- Dollar One" | |
echo "$2 <-- Dollar Two" | |
for ((i=$1; i<=$2; ++i)) ; | |
do | |
echo "i is equal to: $i" | |
if [ $i == 3 ] | |
then | |
echo "I am about to execute ForLoop. i is $i" | |
ForLoop 6 10 | |
echo "ForLoop has been executed. i is $i" | |
fi | |
done | |
} | |
ForLoop 0 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment