×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Simple While Loop

## Simple While Loop

(OP)
I have been beating my head against a wall on something so simple.  Will someone put me out of my misery please

Attached is the simple sheet.  Please tell me where I am going so wrong.

### RE: Simple While Loop

I couldn't see anything wrong.  Then again, I couldn't see anything.  Double check your file that you posted.

### RE: Simple While Loop

(OP)
Well, now I am home and dont have the file.

SS: |h <-- 1
|b <-- 1
|Sa < -- b + h
|  while Sa ≤ 10
|    h <-- h + 1
|return h

the program says basically i have an infinite loop. dont get it
I have done it without the return statement as well and get the same answer.  I should get ss = 9

any ideas?

### RE: Simple While Loop

It seems that your loop increases h, but does not calculate Sa in the loop... My guess is that you should put Sa <-- b+h in the while loop, and then the loop will not be infinite. HTH

### RE: Simple While Loop

(OP)
Tried changing the inequality sign

SS: |h <-- 1
|b <-- 1
|  while Sa < 10
|Sa < -- b + h
|h <-- h + 1
|return h

ss = 10

still should be 9

### RE: Simple While Loop

No, it shouldn't be 9- when Sa is 9, it's still <10 so the loop gets executed one more time. Condition should be Sa<9.

### RE: Simple While Loop

(OP)
Hmmm... I get what you are saying.  The example was a simplistic situation for what I am really trying to calculate.  I attached the mathcad and a pdf just in case.  Am I not passing the arguments correctly?  I have done other loops without a problem, cannot see why this one is not okay.

http://files.engineering.com/getfile.aspx?folder=14fb7143-44d4-4649-86d1-fd2b4343a48f&file=loop_problem.xmcd

### RE: Simple While Loop

Look at the help for the While command. While goes until condition is met. If you are looking for a specific number of loops use the For loop command. It seems the While command start counting from zero and not from one.

### RE: Simple While Loop

(OP)
yea, did that, and all the other internet searches I could, to no avail.  The while command can start from any point, and I have no idea how many iterations it will take to get to my result, hense the reason for using the while loop

(OP)
Anyone?

### RE: Simple While Loop

I have ver. 13, so I couldn't load your .xmcd file, but from the .pdf file, it seems that you don't define Sa before the while loop, so it never is > 25ksi and h stays at 5 mm.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!