home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.msdos.batch.nt      Fun with Windows NT batch files      68,980 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 67,539 of 68,980   
   JJ to Tom Del Rosso   
   Re: FOR /L counting limit   
   21 May 20 13:56:42   
   
   From: jj4public@vfemail.net   
      
   On Wed, 20 May 2020 23:06:50 -0400, Tom Del Rosso wrote:   
   > Tom Del Rosso wrote:   
   >> This counts into the millions if you leave it running, but how high   
   >> will it go?   
   >>   
   >> for /l %%a in   
   >> (1,1,100000000000000000000000000000000000000000000000000000000000000000000)   
   >> do @echo %%a   
   >   
   > Maybe I was too eager to make conversation so I posted the question   
   > before investigating.  Simply starting from a larger number shows that   
   > it is 32 bits, and it rolls over to -2^31.   
   >   
   > What's interesting is that if you start with any number larger than   
   > +2^31-1 then it starts at +2^31-1 and immediately rolls over to -2^31.   
      
   All batch files numbers are 32-bit signed integer, so it's not possible to   
   have literal number which is greater than 0x7FFFFFFF or smaller than   
   -0x80000000. 0x7FFFFFFF+1 is -0x80000000, and (-0x80000000)-1 is 0x7FFFFFFF.   
      
   To make a loop more than 0x7FFFFFFF times, use nested loops. e.g. to split   
   the lower and upper 16-bits or an unsigned 32-bit.   
      
     @echo off   
     for /l %%H in (1,1,65536) (   
       for /l %%L in (1,1,65536) (   
         echo %%H * %%L   
       )   
     )   
      
   Increasing the nesting level can give you loop for more than 32-bits and   
   even higher.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca