MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: nesting while function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56784] Re: [mg56758] nesting while function
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Fri, 6 May 2005 02:59:51 -0400 (EDT)
  • References: <200505051001.GAA22002@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On May 5, 2005, at 6:01 AM, marloo3 at mail15.com wrote:

> Hi
> t = 0; i = 1; j = 1;
> While[i <= 3,
>   While[j <= 2,
>     t = t + 1;
>     j = j + 1];
>   i = i + 1]
>
> give the result for t=2 and not 6 as should be
>
> but
> t = 0; Do[
>          Do[
>              t = t + 1;
>               , {j, 2}];
>   , {i, 3}]
>
> give the value of 6 for t
> is this a wrong behaviour for the "While" function ? or i miss 
> something.

You need to reset j to 0 before starting your inner While loop.

Regards,

Ssezi


  • Prev by Date: Re: nesting while function
  • Next by Date: Re: nesting while function
  • Previous by thread: Re: nesting while function
  • Next by thread: Re: nesting while function