Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25418 > unrolled thread

Set flag/boolean when loop finish?

Started byjonas.thornvall@gmail.com
First post2014-07-17 10:29 -0700
Last post2014-07-17 11:45 -0700
Articles 7 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  Set flag/boolean when loop finish? jonas.thornvall@gmail.com - 2014-07-17 10:29 -0700
    Re: Set flag/boolean when loop finish? jonas.thornvall@gmail.com - 2014-07-17 10:39 -0700
      Re: Set flag/boolean when loop finish? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-07-17 19:06 +0100
        Re: Set flag/boolean when loop finish? jonas.thornvall@gmail.com - 2014-07-17 11:18 -0700
        Re: Set flag/boolean when loop finish? jonas.thornvall@gmail.com - 2014-07-17 11:28 -0700
          Re: Set flag/boolean when loop finish? jonas.thornvall@gmail.com - 2014-07-17 11:40 -0700
            Re: Set flag/boolean when loop finish? jonas.thornvall@gmail.com - 2014-07-17 11:45 -0700

#25418 — Set flag/boolean when loop finish?

Fromjonas.thornvall@gmail.com
Date2014-07-17 10:29 -0700
SubjectSet flag/boolean when loop finish?
Message-ID<6e181cd1-00bd-459b-a219-a32449dac38a@googlegroups.com>
This code seem unecessarily set the flag to one multiple times, how can i condition the while to just set it as it step out of loop?
  
while (i * basemultip <= number && i < bas)
      {
         j = i;
         i ++ ;
         set = 1;
      }

[toc] | [next] | [standalone]


#25419

Fromjonas.thornvall@gmail.com
Date2014-07-17 10:39 -0700
Message-ID<952c9e65-eacb-4808-9498-75b35fce6d8d@googlegroups.com>
In reply to#25418
Den torsdagen den 17:e juli 2014 kl. 19:29:23 UTC+2 skrev jonas.t...@gmail.com:
> This code seem unecessarily set the flag to one multiple times, how can i condition the while to just set it as it step out of loop?
> 
>   
> 
> while (i * basemultip <= number && i < bas)
> 
>       {
> 
>          j = i;
> 
>          i ++ ;
> 
>          set = 1;
> 
>       }

Managed to reduce some conditional checks, well they was unnecessary to start with.

function enctwo(number, bas)
{
   basestr = "";
   basemultip = 1;
   digit = 1;

   while (basemultip < number)
   {
      basemultip = basemultip * bas;
      digit = digit + 1;
   }

   while (number > 0 && digit > 0)
   {
      set = 0;
      i = 0;
      while (i * basemultip <= number && i < bas)
      {
         j = i;
         i ++ ;
         set = 1;
      }
      if (set == 1)
      {
         subtrahend = basemultip * j;
         number = number - subtrahend;
         basestr = basestr + j + " ";
      }
      //else if (set == 0 && number != 0)basestr = basestr + 0 + " ";
      else {basestr = basestr + 0 + " ";}
      basemultip = basemultip / bas;
      digit -- ;
   }
   while (digit > 0)
   {
      basestr = basestr + 0 + " ";
      digit -- ;
   }
   return basestr;
}

[toc] | [prev] | [next] | [standalone]


#25420

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2014-07-17 19:06 +0100
Message-ID<0.72faf399b1fb10aac12d.20140717190623BST.87iomvx3kw.fsf@bsb.me.uk>
In reply to#25419
jonas.thornvall@gmail.com writes:
<snip>
> Managed to reduce some conditional checks, well they was unnecessary
> to start with.
<snip>
>       set = 0;
>       i = 0;
>       while (i * basemultip <= number && i < bas)
>       {
>          j = i;
>          i ++ ;
>          set = 1;
>       }
>       if (set == 1)

Here, the conditions set == 1 and i > 0 are the same.  There's no need
for 'set'.

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#25421

Fromjonas.thornvall@gmail.com
Date2014-07-17 11:18 -0700
Message-ID<5b311ab2-9f87-48c8-974b-fbf6f42c775f@googlegroups.com>
In reply to#25420
Den torsdagen den 17:e juli 2014 kl. 20:06:23 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> 
> <snip>
> 
> > Managed to reduce some conditional checks, well they was unnecessary
> 
> > to start with.
> 
> <snip>
> 
> >       set = 0;
> 
> >       i = 0;
> 
> >       while (i * basemultip <= number && i < bas)
> 
> >       {
> 
> >          j = i;
> 
> >          i ++ ;
> 
> >          set = 1;
> 
> >       }
> 
> >       if (set == 1)
> 
> 
> 
> Here, the conditions set == 1 and i > 0 are the same.  There's no need
> 
> for 'set'.
> 
> 
> 
> <snip>
> 
> -- 
> 
> Ben.

Of course, thanks Ben.

[toc] | [prev] | [next] | [standalone]


#25422

Fromjonas.thornvall@gmail.com
Date2014-07-17 11:28 -0700
Message-ID<871106eb-dfea-467e-8fb9-ffea8c87f3c7@googlegroups.com>
In reply to#25420
Den torsdagen den 17:e juli 2014 kl. 20:06:23 UTC+2 skrev Ben Bacarisse:
> jonas.thornvall@gmail.com writes:
> 
> <snip>
> 
> > Managed to reduce some conditional checks, well they was unnecessary
> 
> > to start with.
> 
> <snip>
> 
> >       set = 0;
> 
> >       i = 0;
> 
> >       while (i * basemultip <= number && i < bas)
> 
> >       {
> 
> >          j = i;
> 
> >          i ++ ;
> 
> >          set = 1;
> 
> >       }
> 
> >       if (set == 1)
> 
> 
> 
> Here, the conditions set == 1 and i > 0 are the same.  There's no need
> 
> for 'set'.
> 
> 
> 
> <snip>
> 
> -- 
> 
> Ben.

Would it be possible to go direct to bijective code from this by reduce the previous digit when a zero appear and make next digit base, and if another 0 follow reduce that base value-1, sort of roll it off?

[toc] | [prev] | [next] | [standalone]


#25423

Fromjonas.thornvall@gmail.com
Date2014-07-17 11:40 -0700
Message-ID<ae0bfc0c-15d3-4159-90d2-52224f44f6c9@googlegroups.com>
In reply to#25422
Den torsdagen den 17:e juli 2014 kl. 20:28:50 UTC+2 skrev jonas.t...@gmail.com:
> Den torsdagen den 17:e juli 2014 kl. 20:06:23 UTC+2 skrev Ben Bacarisse:
> 
> > jonas.thornvall@gmail.com writes:
> 
> > 
> 
> > <snip>
> 
> > 
> 
> > > Managed to reduce some conditional checks, well they was unnecessary
> 
> > 
> 
> > > to start with.
> 
> > 
> 
> > <snip>
> 
> > 
> 
> > >       set = 0;
> 
> > 
> 
> > >       i = 0;
> 
> > 
> 
> > >       while (i * basemultip <= number && i < bas)
> 
> > 
> 
> > >       {
> 
> > 
> 
> > >          j = i;
> 
> > 
> 
> > >          i ++ ;
> 
> > 
> 
> > >          set = 1;
> 
> > 
> 
> > >       }
> 
> > 
> 
> > >       if (set == 1)
> 
> > 
> 
> > 
> 
> > 
> 
> > Here, the conditions set == 1 and i > 0 are the same.  There's no need
> 
> > 
> 
> > for 'set'.
> 
> > 
> 
> > 
> 
> > 
> 
> > <snip>
> 
> > 
> 
> > -- 
> 
> > 
> 
> > Ben.
> 
> 
> 
> Would it be possible to go direct to bijective code from this by reduce the previous digit when a zero appear and make next digit base, and if another 0 follow reduce that base value-1, sort of roll it off?

The nasty case would be when the leading number of the zeros is 1 i guess.

[toc] | [prev] | [next] | [standalone]


#25424

Fromjonas.thornvall@gmail.com
Date2014-07-17 11:45 -0700
Message-ID<634f7356-084d-407a-8c05-9f8608ab2cd1@googlegroups.com>
In reply to#25423
Den torsdagen den 17:e juli 2014 kl. 20:40:36 UTC+2 skrev jonas.t...@gmail.com:
> Den torsdagen den 17:e juli 2014 kl. 20:28:50 UTC+2 skrev jonas.t...@gmail.com:
> 
> > Den torsdagen den 17:e juli 2014 kl. 20:06:23 UTC+2 skrev Ben Bacarisse:
> 
> > 
> 
> > > jonas.thornvall@gmail.com writes:
> 
> > 
> 
> > > 
> 
> > 
> 
> > > <snip>
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > Managed to reduce some conditional checks, well they was unnecessary
> 
> > 
> 
> > > 
> 
> > 
> 
> > > > to start with.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > <snip>
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >       set = 0;
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >       i = 0;
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >       while (i * basemultip <= number && i < bas)
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >       {
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >          j = i;
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >          i ++ ;
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >          set = 1;
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >       }
> 
> > 
> 
> > > 
> 
> > 
> 
> > > >       if (set == 1)
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Here, the conditions set == 1 and i > 0 are the same.  There's no need
> 
> > 
> 
> > > 
> 
> > 
> 
> > > for 'set'.
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > <snip>
> 
> > 
> 
> > > 
> 
> > 
> 
> > > -- 
> 
> > 
> 
> > > 
> 
> > 
> 
> > > Ben.
> 
> > 
> 
> > 
> 
> > 
> 
> > Would it be possible to go direct to bijective code from this by reduce the previous digit when a zero appear and make next digit base, and if another 0 follow reduce that base value-1, sort of roll it off?
> 
> 
> 
> The nasty case would be when the leading number of the zeros is 1 i guess.

And an array approach rather then a string would be necessary.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web