Home All Groups Group Topic Archive Search About
Author
11 May 2005 9:56 AM
Noelia
Hi,

I have written a program to do some probability calculations.
The problem is that I need a 38-deep nested loop and it doesn't seem to like
it. The program is not even compiling!

Is there any limit on the number of nested loops you can have in VB?

Thank you very much.

Author
11 May 2005 10:59 AM
Douglas Marquardt
if i recall correctly, the nested limit is seven levels.

Doug.

Show quote
"Noelia" <Noe***@discussions.microsoft.com> wrote in message news:CA29D9CF-886E-4F4A-A54C-5BC5F3B60D28@microsoft.com...
>
> Hi,
>
> I have written a program to do some probability calculations.
> The problem is that I need a 38-deep nested loop and it doesn't seem to like
> it. The program is not even compiling!
>
> Is there any limit on the number of nested loops you can have in VB?
>
> Thank you very much.
>
Author
11 May 2005 11:08 AM
Noelia
I'm afraid that cannot possibly be correct because I've done programs that
had up to 18 levels.


Show quote
"Douglas Marquardt" wrote:

> if i recall correctly, the nested limit is seven levels.
>
> Doug.
>
> "Noelia" <Noe***@discussions.microsoft.com> wrote in message news:CA29D9CF-886E-4F4A-A54C-5BC5F3B60D28@microsoft.com...
> >
> > Hi,
> >
> > I have written a program to do some probability calculations.
> > The problem is that I need a 38-deep nested loop and it doesn't seem to like
> > it. The program is not even compiling!
> >
> > Is there any limit on the number of nested loops you can have in VB?
> >
> > Thank you very much.
> >
>
>
>
Author
11 May 2005 11:37 AM
Douglas Marquardt
Hi Noelia:

Now that I think about it again... i believe that limit was for nested controls, not loops :-)

Doug.

Show quote
"Noelia" <Noe***@discussions.microsoft.com> wrote in message news:A56740F5-5C65-4193-A115-7461FB04AD27@microsoft.com...
>
> I'm afraid that cannot possibly be correct because I've done programs that
> had up to 18 levels.
>
>
> "Douglas Marquardt" wrote:
>
> > if i recall correctly, the nested limit is seven levels.
> >
> > Doug.
> >
> > "Noelia" <Noe***@discussions.microsoft.com> wrote in message news:CA29D9CF-886E-4F4A-A54C-5BC5F3B60D28@microsoft.com...
> > >
> > > Hi,
> > >
> > > I have written a program to do some probability calculations.
> > > The problem is that I need a 38-deep nested loop and it doesn't seem to like
> > > it. The program is not even compiling!
> > >
> > > Is there any limit on the number of nested loops you can have in VB?
> > >
> > > Thank you very much.
> > >
> >
> >
> >
Author
11 May 2005 11:10 AM
Tony Proctor
You've got to be kidding!!

Even if each loop only had 2 iterations, the inner-most would get executed
about 10^11 times, i.e. about 100 billion!! You could be waiting quite a
while for it to finish.

        Tony Proctor

Show quote
"Noelia" <Noe***@discussions.microsoft.com> wrote in message
news:CA29D9CF-886E-4F4A-A54C-5BC5F3B60D28@microsoft.com...
>
> Hi,
>
> I have written a program to do some probability calculations.
> The problem is that I need a 38-deep nested loop and it doesn't seem to
like
> it. The program is not even compiling!
>
> Is there any limit on the number of nested loops you can have in VB?
>
> Thank you very much.
>
Author
11 May 2005 12:18 PM
Charlie
That's what I was thinking.  There's GOT to be a better way to solve the
problem than 38 nested loops!

Show quote
"Tony Proctor" wrote:

> You've got to be kidding!!
>
> Even if each loop only had 2 iterations, the inner-most would get executed
> about 10^11 times, i.e. about 100 billion!! You could be waiting quite a
> while for it to finish.
>
>         Tony Proctor
>
> "Noelia" <Noe***@discussions.microsoft.com> wrote in message
> news:CA29D9CF-886E-4F4A-A54C-5BC5F3B60D28@microsoft.com...
> >
> > Hi,
> >
> > I have written a program to do some probability calculations.
> > The problem is that I need a 38-deep nested loop and it doesn't seem to
> like
> > it. The program is not even compiling!
> >
> > Is there any limit on the number of nested loops you can have in VB?
> >
> > Thank you very much.
> >
>
>
>
Author
11 May 2005 11:55 AM
Al Reid
"Noelia" <Noe***@discussions.microsoft.com> wrote in message news:CA29D9CF-886E-4F4A-A54C-5BC5F3B60D28@microsoft.com...
>
> Hi,
>
> I have written a program to do some probability calculations.
> The problem is that I need a 38-deep nested loop and it doesn't seem to like
> it. The program is not even compiling!
>
> Is there any limit on the number of nested loops you can have in VB?
>
> Thank you very much.
>

I just did a quick test with 38 nested "For-Next" loops and Do loops without any problem.  Perhaps you've made a typo or left out a
Next or Loop.  Try Ctrl-F5 and not the error message and the line that does not compile.

--

Al Reid
Author
11 May 2005 12:42 PM
Noelia
Show quote
"Al Reid" wrote:

> > I have written a program to do some probability calculations.
> > The problem is that I need a 38-deep nested loop and it doesn't seem to like
> > it. The program is not even compiling!
> >
> > Is there any limit on the number of nested loops you can have in VB?
> >
> > Thank you very much.
>
> I just did a quick test with 38 nested "For-Next" loops and Do loops without any problem.  Perhaps you've made a typo or left out a
> Next or Loop.  Try Ctrl-F5 and not the error message and the line that does not compile.
>
> --
>
> Al Reid

When I try to compile the program it doesn't report any errors, it just gets
stuck in the compilation... I've tried Ctrl-F5 like you suggest, the program
is still running... If it displays any error messages I'll post them.
Author
11 May 2005 12:56 PM
Al Reid
Show quote
"Noelia" <Noe***@discussions.microsoft.com> wrote in message news:5156DBBD-9A1D-4A8F-AD8A-4F319B9CF67F@microsoft.com...
> "Al Reid" wrote:
>
> > > I have written a program to do some probability calculations.
> > > The problem is that I need a 38-deep nested loop and it doesn't seem to like
> > > it. The program is not even compiling!
> > >
> > > Is there any limit on the number of nested loops you can have in VB?
> > >
> > > Thank you very much.
> >
> > I just did a quick test with 38 nested "For-Next" loops and Do loops without any problem.  Perhaps you've made a typo or left
out a
> > Next or Loop.  Try Ctrl-F5 and not the error message and the line that does not compile.
> >
> > --
> >
> > Al Reid
>
> When I try to compile the program it doesn't report any errors, it just gets
> stuck in the compilation... I've tried Ctrl-F5 like you suggest, the program
> is still running... If it displays any error messages I'll post them.

It sounds like it has compiled and is running.  Either the algorithm is taking much longer than you expected or it is stuck in a
loop.

Hit ctrl-Break to enter debug mode, then press F8 to single step through the code to see what is happening.

--
Al Reid
Author
11 May 2005 1:20 PM
Noelia
Show quote
> > > > I have written a program to do some probability calculations.
> > > > The problem is that I need a 38-deep nested loop and it doesn't seem to like
> > > > it. The program is not even compiling!
> > > >
> > > > Is there any limit on the number of nested loops you can have in VB?
> > > >
> > > > Thank you very much.
> > >
> > > I just did a quick test with 38 nested "For-Next" loops and Do loops without any problem.  Perhaps you've made a typo or left
> out a
> > > Next or Loop.  Try Ctrl-F5 and not the error message and the line that does not compile.
> > >
> > > --
> > >
> > > Al Reid
> >
> > When I try to compile the program it doesn't report any errors, it just gets
> > stuck in the compilation... I've tried Ctrl-F5 like you suggest, the program
> > is still running... If it displays any error messages I'll post them.
>
> It sounds like it has compiled and is running.  Either the algorithm is taking much longer than you expected or it is stuck in a
> loop.
>
> Hit ctrl-Break to enter debug mode, then press F8 to single step through the code to see what is happening.
>
> --
> Al Reid
>

It executes the code inside the loops...  it is a bit slow (each loop does 6
iterations)
but it seems to get through no problem... I've done about 30 iterations and
it hasn't stopped or reported any problems...
Author
11 May 2005 12:11 PM
Jan Hyde
Noelia <Noe***@discussions.microsoft.com>'s wild thoughts
were released on Wed, 11 May 2005 02:56:02 -0700 bearing the
following fruit:

>
>Hi,
>
>I have written a program to do some probability calculations.
>The problem is that I need a 38-deep nested loop and it doesn't seem to like
>it. The program is not even compiling!
>
>Is there any limit on the number of nested loops you can have in VB?
>
>Thank you very much.

38 nested loops?!

I think you'd be better of posting code and telling us what
you want to achieve.



Jan Hyde (VB MVP)

--
Police arrested two kids yesterday, one was drinking battery acid, the
other was eating fireworks.

They charged one and let the other one off.

[Abolish the TV Licence - http://www.tvlicensing.biz/]
Author
11 May 2005 12:46 PM
Noelia
The program tries to calculate the expected win value of a game.
There are 37 cells in a hexagonal grid. At the beginning of the game each
cell is set to a random number drawn from a specific distribution. One of the
cells is chosen and its value and its neighbours values are displayed to the
player. The player can then choose to move to one of the neighbours hoping to
get a higher prize or just take the prize he's offered.

Show quote
"Jan Hyde" wrote:

> >I have written a program to do some probability calculations.
> >The problem is that I need a 38-deep nested loop and it doesn't seem to like
> >it. The program is not even compiling!
> >
> >Is there any limit on the number of nested loops you can have in VB?
> >
> >Thank you very much.
>
> 38 nested loops?!
>
> I think you'd be better of posting code and telling us what
> you want to achieve.
>
> Jan Hyde (VB MVP)
>
Author
11 May 2005 2:17 PM
Jan Hyde
Noelia <Noe***@discussions.microsoft.com>'s wild thoughts
were released on Wed, 11 May 2005 05:46:06 -0700 bearing the
following fruit:

>The program tries to calculate the expected win value of a game.
>There are 37 cells in a hexagonal grid. At the beginning of the game each
>cell is set to a random number drawn from a specific distribution. One of the
>cells is chosen and its value and its neighbours values are displayed to the
>player. The player can then choose to move to one of the neighbours hoping to
>get a higher prize or just take the prize he's offered.

Try the newsgroup

rec.puzzles

Finding the most efficient algorithm is something they like
doing over there.




Show quote
>"Jan Hyde" wrote:
>
>> >I have written a program to do some probability calculations.
>> >The problem is that I need a 38-deep nested loop and it doesn't seem to like
>> >it. The program is not even compiling!
>> >
>> >Is there any limit on the number of nested loops you can have in VB?
>> >
>> >Thank you very much.
>>
>> 38 nested loops?!
>>
>> I think you'd be better of posting code and telling us what
>> you want to achieve.
>>
>> Jan Hyde (VB MVP)
>>


Jan Hyde (VB MVP)

--
Migration: A headache birds get when they fly down for the winter.
(Richard Lederer)

[Abolish the TV Licence - http://www.tvlicensing.biz/]
Author
11 May 2005 3:40 PM
Noelia
Thanks!!


Show quote
"Jan Hyde" wrote:

> Noelia <Noe***@discussions.microsoft.com>'s wild thoughts
> were released on Wed, 11 May 2005 05:46:06 -0700 bearing the
> following fruit:
>
> >The program tries to calculate the expected win value of a game.
> >There are 37 cells in a hexagonal grid. At the beginning of the game each
> >cell is set to a random number drawn from a specific distribution. One of the
> >cells is chosen and its value and its neighbours values are displayed to the
> >player. The player can then choose to move to one of the neighbours hoping to
> >get a higher prize or just take the prize he's offered.
>
> Try the newsgroup
>
> rec.puzzles
>
> Finding the most efficient algorithm is something they like
> doing over there.
>
>
>
>
> >"Jan Hyde" wrote:
> >
> >> >I have written a program to do some probability calculations.
> >> >The problem is that I need a 38-deep nested loop and it doesn't seem to like
> >> >it. The program is not even compiling!
> >> >
> >> >Is there any limit on the number of nested loops you can have in VB?
> >> >
> >> >Thank you very much.
> >>
> >> 38 nested loops?!
> >>
> >> I think you'd be better of posting code and telling us what
> >> you want to achieve.
> >>
> >> Jan Hyde (VB MVP)
> >>
>
>
> Jan Hyde (VB MVP)
>
> --
> Migration: A headache birds get when they fly down for the winter.
> (Richard Lederer)
>
> [Abolish the TV Licence - http://www.tvlicensing.biz/]
>
>
Author
12 May 2005 1:52 AM
Randy Birch
I would think then that the most the code would have to execute is six
tests, not 38. And less for those on the outside edges and none within
nested loops.

Rather than brute-force calculate the options, would it not be better to
create a 37x6 array, and populate that with the value of the adjacent cells.
Then you just have to look up the cell and examine the numbers on the six
sides.

IOW, if you create the array dim c(1 to 38, 1 to 6) then for cell 1
(upper-top cell) you'd have:

c(1,1) = 0  'top outer edge, an edge cell thus no value
c(1,2) = 0  'cell at 2 o'clock, no cell, thus no value
c(1,3) = 6  'cell at 4 o'clock
c(1,4) = 4  'cell at 6 o'clock
c(1,5) = 0  'cell at 8 o'clock, an edge cell thus no value
c(1,6) = 0 ' cell at 10 o'clock, an edge cell thus no value

If the user selects cell 1, you only have to look at the six values to see
what adjacent cells have. (Let's assume for discussion cell 1 was given the
value of 8)

Setting up the initial array would be the trick, since - now looking at the
cell next to cell 1 at 4 o'clock - you have to now include the value for
cell 1 in the array for the cell's 10 o'clock position, i.e. ... (I don't
have your layout matrix so the index for the first dimension is a guess at
best) ...

c(7,1) = x 'top edge
c(7,2) = x  'cell at 2 o'clock
c(7,3) = x   'cell at 4 o'clock
c(7,4) = x  'cell at 6 o'clock
c(7,5) = x  'cell at 8 o'clock
c(7,6) = 8  'cell at 10 o'clock, 8 is the value of cell 1

.... and so on for all the cells in your matrix.
--

Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
----------------------------------------------------------------------------
Read. Decide. Sign the petition to Microsoft.
http://classicvb.org/petition/
----------------------------------------------------------------------------



Show quote
"Noelia" <Noe***@discussions.microsoft.com> wrote in message
news:641BB711-5F39-4D38-9647-C2A1439B940D@microsoft.com...
: The program tries to calculate the expected win value of a game.
: There are 37 cells in a hexagonal grid. At the beginning of the game each
: cell is set to a random number drawn from a specific distribution. One of
the
: cells is chosen and its value and its neighbours values are displayed to
the
: player. The player can then choose to move to one of the neighbours hoping
to
: get a higher prize or just take the prize he's offered.
:
: "Jan Hyde" wrote:
:
: > >I have written a program to do some probability calculations.
: > >The problem is that I need a 38-deep nested loop and it doesn't seem to
like
: > >it. The program is not even compiling!
: > >
: > >Is there any limit on the number of nested loops you can have in VB?
: > >
: > >Thank you very much.
: >
: > 38 nested loops?!
: >
: > I think you'd be better of posting code and telling us what
: > you want to achieve.
: >
: > Jan Hyde (VB MVP)
: >
Author
12 May 2005 8:06 AM
Noelia
Randy, thanks for your message.
What you suggest is part of the strategy for choosing to move to another
cell or collect the prize on offer.
However, to calculate the overall expected value that's not enough.
For each state of the system you have to know what the expected value is,
which you calculate by applying the strategy (something quite similar to what
you have explained).
Then, the overall expected value is calculated by adding up the result of
multiplying the expect value for each state times the probability of starting
in that state.

What the 38 loops do is set up the state of the system at the start of the
game.
37 of those loops determine the values of the cells and the 38th loop
determines the centre at the start of the game.
Note that at each step only the values of the cell selected as the centre
and its neighbours are displayed.
The player, given an initial offer, can make 4 selections. At each step he
can only select to move to one of the neighbours of the selected centre.
Show quote
"Randy Birch" wrote:

> I would think then that the most the code would have to execute is six
> tests, not 38. And less for those on the outside edges and none within
> nested loops.
>
> Rather than brute-force calculate the options, would it not be better to
> create a 37x6 array, and populate that with the value of the adjacent cells.
> Then you just have to look up the cell and examine the numbers on the six
> sides.
>
> IOW, if you create the array dim c(1 to 38, 1 to 6) then for cell 1
> (upper-top cell) you'd have:
>
> c(1,1) = 0  'top outer edge, an edge cell thus no value
> c(1,2) = 0  'cell at 2 o'clock, no cell, thus no value
> c(1,3) = 6  'cell at 4 o'clock
> c(1,4) = 4  'cell at 6 o'clock
> c(1,5) = 0  'cell at 8 o'clock, an edge cell thus no value
> c(1,6) = 0 ' cell at 10 o'clock, an edge cell thus no value
>
> If the user selects cell 1, you only have to look at the six values to see
> what adjacent cells have. (Let's assume for discussion cell 1 was given the
> value of 8)
>
> Setting up the initial array would be the trick, since - now looking at the
> cell next to cell 1 at 4 o'clock - you have to now include the value for
> cell 1 in the array for the cell's 10 o'clock position, i.e. ... (I don't
> have your layout matrix so the index for the first dimension is a guess at
> best) ...
>
> c(7,1) = x 'top edge
> c(7,2) = x  'cell at 2 o'clock
> c(7,3) = x   'cell at 4 o'clock
> c(7,4) = x  'cell at 6 o'clock
> c(7,5) = x  'cell at 8 o'clock
> c(7,6) = 8  'cell at 10 o'clock, 8 is the value of cell 1
>
> .... and so on for all the cells in your matrix.
> --
>
> Randy Birch
> MS MVP Visual Basic
> http://vbnet.mvps.org/
> ----------------------------------------------------------------------------
> Read. Decide. Sign the petition to Microsoft.
> http://classicvb.org/petition/
> ----------------------------------------------------------------------------
>
>
>
> "Noelia" <Noe***@discussions.microsoft.com> wrote in message
> news:641BB711-5F39-4D38-9647-C2A1439B940D@microsoft.com...
> : The program tries to calculate the expected win value of a game.
> : There are 37 cells in a hexagonal grid. At the beginning of the game each
> : cell is set to a random number drawn from a specific distribution. One of
> the
> : cells is chosen and its value and its neighbours values are displayed to
> the
> : player. The player can then choose to move to one of the neighbours hoping
> to
> : get a higher prize or just take the prize he's offered.
> :
> : "Jan Hyde" wrote:
> :
> : > >I have written a program to do some probability calculations.
> : > >The problem is that I need a 38-deep nested loop and it doesn't seem to
> like
> : > >it. The program is not even compiling!
> : > >
> : > >Is there any limit on the number of nested loops you can have in VB?
> : > >
> : > >Thank you very much.
> : >
> : > 38 nested loops?!
> : >
> : > I think you'd be better of posting code and telling us what
> : > you want to achieve.
> : >
> : > Jan Hyde (VB MVP)
> : >
>
>
Author
12 May 2005 9:05 AM
NickHK
Noelia,
Not that I know much about it, but there has been talk here before on a
Finite State Machine. Not sure if would be applicable to your situation.
Seems like it would Andrew Faust's area.

NickHk

Show quote
"Noelia" <Noe***@discussions.microsoft.com> wrote in message
news:C60C5905-4D8C-4968-B820-AB031D5252C6@microsoft.com...
> Randy, thanks for your message.
> What you suggest is part of the strategy for choosing to move to another
> cell or collect the prize on offer.
> However, to calculate the overall expected value that's not enough.
> For each state of the system you have to know what the expected value is,
> which you calculate by applying the strategy (something quite similar to
what
> you have explained).
> Then, the overall expected value is calculated by adding up the result of
> multiplying the expect value for each state times the probability of
starting
> in that state.
>
> What the 38 loops do is set up the state of the system at the start of the
> game.
> 37 of those loops determine the values of the cells and the 38th loop
> determines the centre at the start of the game.
> Note that at each step only the values of the cell selected as the centre
> and its neighbours are displayed.
> The player, given an initial offer, can make 4 selections. At each step he
> can only select to move to one of the neighbours of the selected centre.
> "Randy Birch" wrote:
>
> > I would think then that the most the code would have to execute is six
> > tests, not 38. And less for those on the outside edges and none within
> > nested loops.
> >
> > Rather than brute-force calculate the options, would it not be better to
> > create a 37x6 array, and populate that with the value of the adjacent
cells.
> > Then you just have to look up the cell and examine the numbers on the
six
> > sides.
> >
> > IOW, if you create the array dim c(1 to 38, 1 to 6) then for cell 1
> > (upper-top cell) you'd have:
> >
> > c(1,1) = 0  'top outer edge, an edge cell thus no value
> > c(1,2) = 0  'cell at 2 o'clock, no cell, thus no value
> > c(1,3) = 6  'cell at 4 o'clock
> > c(1,4) = 4  'cell at 6 o'clock
> > c(1,5) = 0  'cell at 8 o'clock, an edge cell thus no value
> > c(1,6) = 0 ' cell at 10 o'clock, an edge cell thus no value
> >
> > If the user selects cell 1, you only have to look at the six values to
see
> > what adjacent cells have. (Let's assume for discussion cell 1 was given
the
> > value of 8)
> >
> > Setting up the initial array would be the trick, since - now looking at
the
> > cell next to cell 1 at 4 o'clock - you have to now include the value for
> > cell 1 in the array for the cell's 10 o'clock position, i.e. ... (I
don't
> > have your layout matrix so the index for the first dimension is a guess
at
> > best) ...
> >
> > c(7,1) = x 'top edge
> > c(7,2) = x  'cell at 2 o'clock
> > c(7,3) = x   'cell at 4 o'clock
> > c(7,4) = x  'cell at 6 o'clock
> > c(7,5) = x  'cell at 8 o'clock
> > c(7,6) = 8  'cell at 10 o'clock, 8 is the value of cell 1
> >
> > .... and so on for all the cells in your matrix.
> > --
> >
> > Randy Birch
> > MS MVP Visual Basic
> > http://vbnet.mvps.org/
>
> --------------------------------------------------------------------------
--
> > Read. Decide. Sign the petition to Microsoft.
> > http://classicvb.org/petition/
>
> --------------------------------------------------------------------------
--
> >
> >
> >
> > "Noelia" <Noe***@discussions.microsoft.com> wrote in message
> > news:641BB711-5F39-4D38-9647-C2A1439B940D@microsoft.com...
> > : The program tries to calculate the expected win value of a game.
> > : There are 37 cells in a hexagonal grid. At the beginning of the game
each
> > : cell is set to a random number drawn from a specific distribution. One
of
> > the
> > : cells is chosen and its value and its neighbours values are displayed
to
> > the
> > : player. The player can then choose to move to one of the neighbours
hoping
> > to
> > : get a higher prize or just take the prize he's offered.
> > :
> > : "Jan Hyde" wrote:
> > :
> > : > >I have written a program to do some probability calculations.
> > : > >The problem is that I need a 38-deep nested loop and it doesn't
seem to
> > like
> > : > >it. The program is not even compiling!
> > : > >
> > : > >Is there any limit on the number of nested loops you can have in
VB?
> > : > >
> > : > >Thank you very much.
> > : >
> > : > 38 nested loops?!
> > : >
> > : > I think you'd be better of posting code and telling us what
> > : > you want to achieve.
> > : >
> > : > Jan Hyde (VB MVP)
> > : >
> >
> >
Author
12 May 2005 2:12 PM
Noelia
Nick,

That sounds like it might point me in the right direction. I've tried to
find threads about the Finite State Machine or Andrew Faust  but was not
successful. Could you please let me know how to get to that discussion.

Thank you very much!
noelia

Show quote
"NickHK" wrote:

> Noelia,
> Not that I know much about it, but there has been talk here before on a
> Finite State Machine. Not sure if would be applicable to your situation.
> Seems like it would Andrew Faust's area.
>
> NickHk
>
> "Noelia" <Noe***@discussions.microsoft.com> wrote in message
> news:C60C5905-4D8C-4968-B820-AB031D5252C6@microsoft.com...
> > Randy, thanks for your message.
> > What you suggest is part of the strategy for choosing to move to another
> > cell or collect the prize on offer.
> > However, to calculate the overall expected value that's not enough.
> > For each state of the system you have to know what the expected value is,
> > which you calculate by applying the strategy (something quite similar to
> what
> > you have explained).
> > Then, the overall expected value is calculated by adding up the result of
> > multiplying the expect value for each state times the probability of
> starting
> > in that state.
> >
> > What the 38 loops do is set up the state of the system at the start of the
> > game.
> > 37 of those loops determine the values of the cells and the 38th loop
> > determines the centre at the start of the game.
> > Note that at each step only the values of the cell selected as the centre
> > and its neighbours are displayed.
> > The player, given an initial offer, can make 4 selections. At each step he
> > can only select to move to one of the neighbours of the selected centre.
> > "Randy Birch" wrote:
> >
> > > I would think then that the most the code would have to execute is six
> > > tests, not 38. And less for those on the outside edges and none within
> > > nested loops.
> > >
> > > Rather than brute-force calculate the options, would it not be better to
> > > create a 37x6 array, and populate that with the value of the adjacent
> cells.
> > > Then you just have to look up the cell and examine the numbers on the
> six
> > > sides.
> > >
> > > IOW, if you create the array dim c(1 to 38, 1 to 6) then for cell 1
> > > (upper-top cell) you'd have:
> > >
> > > c(1,1) = 0  'top outer edge, an edge cell thus no value
> > > c(1,2) = 0  'cell at 2 o'clock, no cell, thus no value
> > > c(1,3) = 6  'cell at 4 o'clock
> > > c(1,4) = 4  'cell at 6 o'clock
> > > c(1,5) = 0  'cell at 8 o'clock, an edge cell thus no value
> > > c(1,6) = 0 ' cell at 10 o'clock, an edge cell thus no value
> > >
> > > If the user selects cell 1, you only have to look at the six values to
> see
> > > what adjacent cells have. (Let's assume for discussion cell 1 was given
> the
> > > value of 8)
> > >
> > > Setting up the initial array would be the trick, since - now looking at
> the
> > > cell next to cell 1 at 4 o'clock - you have to now include the value for
> > > cell 1 in the array for the cell's 10 o'clock position, i.e. ... (I
> don't
> > > have your layout matrix so the index for the first dimension is a guess
> at
> > > best) ...
> > >
> > > c(7,1) = x 'top edge
> > > c(7,2) = x  'cell at 2 o'clock
> > > c(7,3) = x   'cell at 4 o'clock
> > > c(7,4) = x  'cell at 6 o'clock
> > > c(7,5) = x  'cell at 8 o'clock
> > > c(7,6) = 8  'cell at 10 o'clock, 8 is the value of cell 1
> > >
> > > .... and so on for all the cells in your matrix.
> > > --
> > >
> > > Randy Birch
> > > MS MVP Visual Basic
> > > http://vbnet.mvps.org/
> >
> > --------------------------------------------------------------------------
> --
> > > Read. Decide. Sign the petition to Microsoft.
> > > http://classicvb.org/petition/
> >
> > --------------------------------------------------------------------------
> --
> > >
> > >
> > >
> > > "Noelia" <Noe***@discussions.microsoft.com> wrote in message
> > > news:641BB711-5F39-4D38-9647-C2A1439B940D@microsoft.com...
> > > : The program tries to calculate the expected win value of a game.
> > > : There are 37 cells in a hexagonal grid. At the beginning of the game
> each
> > > : cell is set to a random number drawn from a specific distribution. One
> of
> > > the
> > > : cells is chosen and its value and its neighbours values are displayed
> to
> > > the
> > > : player. The player can then choose to move to one of the neighbours
> hoping
> > > to
> > > : get a higher prize or just take the prize he's offered.
> > > :
> > > : "Jan Hyde" wrote:
> > > :
> > > : > >I have written a program to do some probability calculations.
> > > : > >The problem is that I need a 38-deep nested loop and it doesn't
> seem to
> > > like
> > > : > >it. The program is not even compiling!
> > > : > >
> > > : > >Is there any limit on the number of nested loops you can have in
> VB?
> > > : > >
> > > : > >Thank you very much.
> > > : >
> > > : > 38 nested loops?!
> > > : >
> > > : > I think you'd be better of posting code and telling us what
> > > : > you want to achieve.
> > > : >
> > > : > Jan Hyde (VB MVP)
> > > : >
> > >
> > >
>
>
>
Author
13 May 2005 1:41 AM
NickHK
Noelia,
There wasn't much specific, but I got the idea it might apply in your
situation:
http://groups.google.co.uk/group/microsoft.public.vb.general.discussion/sear
ch?group=microsoft.public.vb.general.discussion&q=%22Finite+State+Machine%22
&qt_g=1&searchnow=Search+this+group

Or more generally on the net:
http://www.google.co.uk/search?hl=en&q=%22Finite+State+Machine%22+VB&btnG=Go
ogle+Search

NickHK

Show quote
"Noelia" <Noe***@discussions.microsoft.com> wrote in message
news:B916F49B-3BFE-4D5F-A3F5-7BD16C9ED4D4@microsoft.com...
> Nick,
>
> That sounds like it might point me in the right direction. I've tried to
> find threads about the Finite State Machine or Andrew Faust  but was not
> successful. Could you please let me know how to get to that discussion.
>
> Thank you very much!
> noelia
>
> "NickHK" wrote:
>
> > Noelia,
> > Not that I know much about it, but there has been talk here before on a
> > Finite State Machine. Not sure if would be applicable to your situation.
> > Seems like it would Andrew Faust's area.
> >
> > NickHk
> >
> > "Noelia" <Noe***@discussions.microsoft.com> wrote in message
> > news:C60C5905-4D8C-4968-B820-AB031D5252C6@microsoft.com...
> > > Randy, thanks for your message.
> > > What you suggest is part of the strategy for choosing to move to
another
> > > cell or collect the prize on offer.
> > > However, to calculate the overall expected value that's not enough.
> > > For each state of the system you have to know what the expected value
is,
> > > which you calculate by applying the strategy (something quite similar
to
> > what
> > > you have explained).
> > > Then, the overall expected value is calculated by adding up the result
of
> > > multiplying the expect value for each state times the probability of
> > starting
> > > in that state.
> > >
> > > What the 38 loops do is set up the state of the system at the start of
the
> > > game.
> > > 37 of those loops determine the values of the cells and the 38th loop
> > > determines the centre at the start of the game.
> > > Note that at each step only the values of the cell selected as the
centre
> > > and its neighbours are displayed.
> > > The player, given an initial offer, can make 4 selections. At each
step he
> > > can only select to move to one of the neighbours of the selected
centre.
> > > "Randy Birch" wrote:
> > >
> > > > I would think then that the most the code would have to execute is
six
> > > > tests, not 38. And less for those on the outside edges and none
within
> > > > nested loops.
> > > >
> > > > Rather than brute-force calculate the options, would it not be
better to
> > > > create a 37x6 array, and populate that with the value of the
adjacent
> > cells.
> > > > Then you just have to look up the cell and examine the numbers on
the
> > six
> > > > sides.
> > > >
> > > > IOW, if you create the array dim c(1 to 38, 1 to 6) then for cell 1
> > > > (upper-top cell) you'd have:
> > > >
> > > > c(1,1) = 0  'top outer edge, an edge cell thus no value
> > > > c(1,2) = 0  'cell at 2 o'clock, no cell, thus no value
> > > > c(1,3) = 6  'cell at 4 o'clock
> > > > c(1,4) = 4  'cell at 6 o'clock
> > > > c(1,5) = 0  'cell at 8 o'clock, an edge cell thus no value
> > > > c(1,6) = 0 ' cell at 10 o'clock, an edge cell thus no value
> > > >
> > > > If the user selects cell 1, you only have to look at the six values
to
> > see
> > > > what adjacent cells have. (Let's assume for discussion cell 1 was
given
> > the
> > > > value of 8)
> > > >
> > > > Setting up the initial array would be the trick, since - now looking
at
> > the
> > > > cell next to cell 1 at 4 o'clock - you have to now include the value
for
> > > > cell 1 in the array for the cell's 10 o'clock position, i.e. ... (I
> > don't
> > > > have your layout matrix so the index for the first dimension is a
guess
> > at
> > > > best) ...
> > > >
> > > > c(7,1) = x 'top edge
> > > > c(7,2) = x  'cell at 2 o'clock
> > > > c(7,3) = x   'cell at 4 o'clock
> > > > c(7,4) = x  'cell at 6 o'clock
> > > > c(7,5) = x  'cell at 8 o'clock
> > > > c(7,6) = 8  'cell at 10 o'clock, 8 is the value of cell 1
> > > >
> > > > .... and so on for all the cells in your matrix.
> > > > --
> > > >
> > > > Randy Birch
> > > > MS MVP Visual Basic
> > > > http://vbnet.mvps.org/
> > >
> >
> --------------------------------------------------------------------------
> > --
> > > > Read. Decide. Sign the petition to Microsoft.
> > > > http://classicvb.org/petition/
> > >
> >
> --------------------------------------------------------------------------
> > --
> > > >
> > > >
> > > >
> > > > "Noelia" <Noe***@discussions.microsoft.com> wrote in message
> > > > news:641BB711-5F39-4D38-9647-C2A1439B940D@microsoft.com...
> > > > : The program tries to calculate the expected win value of a game.
> > > > : There are 37 cells in a hexagonal grid. At the beginning of the
game
> > each
> > > > : cell is set to a random number drawn from a specific distribution.
One
> > of
> > > > the
> > > > : cells is chosen and its value and its neighbours values are
displayed
> > to
> > > > the
> > > > : player. The player can then choose to move to one of the
neighbours
> > hoping
> > > > to
> > > > : get a higher prize or just take the prize he's offered.
> > > > :
> > > > : "Jan Hyde" wrote:
> > > > :
> > > > : > >I have written a program to do some probability calculations.
> > > > : > >The problem is that I need a 38-deep nested loop and it doesn't
> > seem to
> > > > like
> > > > : > >it. The program is not even compiling!
> > > > : > >
> > > > : > >Is there any limit on the number of nested loops you can have
in
> > VB?
> > > > : > >
> > > > : > >Thank you very much.
> > > > : >
> > > > : > 38 nested loops?!
> > > > : >
> > > > : > I think you'd be better of posting code and telling us what
> > > > : > you want to achieve.
> > > > : >
> > > > : > Jan Hyde (VB MVP)
> > > > : >
> > > >
> > > >
> >
> >
> >

AddThis Social Bookmark Button