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


Groups > comp.lang.javascript > #25419

Re: Set flag/boolean when loop finish?

Newsgroups comp.lang.javascript
Date 2014-07-17 10:39 -0700
References <6e181cd1-00bd-459b-a219-a32449dac38a@googlegroups.com>
Message-ID <952c9e65-eacb-4808-9498-75b35fce6d8d@googlegroups.com> (permalink)
Subject Re: Set flag/boolean when loop finish?
From jonas.thornvall@gmail.com

Show all headers | View raw


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;
}

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web