Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

understanding loop

Status
Not open for further replies.

pagheca

Mechanical
Nov 27, 2005
31
Hi everyone,
I would like to simulate as a start the throw of two dices and want to check how many times I get a certain value from 0 to 12.

I used a while loop (see attachment) but it doesn't work as it never exit the loop. N is the number of throws to try. Y[0,P is a vector, j is an index. Z is the histogram that should contain the result (but actually I guess there is a problem also here as it looks I never compute any of the instruction from D <- to j+1).

Where am I wrong? Must be very easy but I didn't get probably the logic of these loop programming. Thanks for any help,
pagheca
 
Replies continue below

Recommended for you

The loop is executing, but all it's doing is incrementing Y[0,0 from 0 to 100. Change the second line of your loop to the following to see the total for each possibility:

Y[0,(D-2) := Y[0,(D-2) + 1

[ is vector subscript

Peter
 
Also, you have one extra column in Y, there are only 11 possibilities not 12.

Peter
 
Well, one die could end up on its edge, I suppose...

TTFN

FAQ731-376
 
ok, thanks for all the advice! Now it works.
pagheca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor