LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need Help with a "while" loop (https://www.linuxquestions.org/questions/linux-newbie-8/need-help-with-a-while-loop-4175474340/)

jefferj54 08-22-2013 08:16 PM

Need Help with a "while" loop
 
Hi,

I need some help with looping. I need a portion of a script where I ask for two numbers to be entered, which also continue to ("while") loop until "q" is pressed to quit the loop.

The numbers are ultimately added, but what I am looking for is that I need the two numbers that are entered to be looped.

Here is my present script (below) which adds two numbers. Please be gentle as I am truly "a newbie."

Thank You,

joe.


echo "Enter one number"
read num1
echo “Enter another number”
read num2
sum=$((num1 + num2))
echo "The sum is = $sum"

SAbhi 08-22-2013 08:49 PM

you did'nt mentioned how the no's are looped, so considering this is not your school assignment, let me give you a usage of while loop so you try looping your variables the way you want them and let us know where you stuck.

syntax:
Code:

while [condition]
do
[statements to be looped]
...........
...........
done

although i cant see any good use of looping two variables in a loop just for adding them instead sounds like a home assignment.

cheers :)

HMW 08-23-2013 12:47 AM

Like SAbhi wrote above, it's not really clear what you are trying to achieve here. I honestly don't understand your question, specifically:
Quote:

The numbers are ultimately added, but what I am looking for is that I need the two numbers that are entered to be looped
How? Why?

Best of luck, and get back with more info, then we might be able to help out.

HMW


All times are GMT -5. The time now is 02:56 PM.