[Bro] for loop

scott campbell scampbell at lbl.gov
Wed Sep 21 10:13:07 PDT 2005


bchen at cs.ucf.edu wrote:
> Thanks Scott. This is a good suggestion. but what if the upper bound (10 
> in my
> example) is a variable? The corresponding c code is like this:
> 
> for(i=0;i<max;i++){}
> 
> I also want to the for loop executes from 0 to max in increasing order. 
> How to
> do that?
> 
> thanks
> 
> Bing
> 
> 
> Quoting scott campbell <scampbell at lbl.gov>:
> 
>> bchen at cs.ucf.edu wrote:
>>
>>> Hello everyone,
>>>      Doese anyone know how to implement for loop statement similar 
>>> with the
>>> following C code:
>>>
>>> for(i=0;i<10;i++){
>>> }
>>>
>>> thanks
>>>
>>> Bing
>>>
>>>
>>> _______________________________________________
>>> Bro mailing list
>>> bro at bro-ids.org
>>> http://mailman.ICSI.Berkeley.EDU/mailman/listinfo/bro
>>
>>
>> I had to do this once and did something like:
>>
>> const LIST = { 1,2,3,4,5,6 };
>> local i: count;
>>
>> for ( i in LIST )
>>     {
>>
>>     }
>>
>> I can look for the code in the morning (as the LIST defn is probably 
>> not correct), and perhaps someone may come up with something less vile.
>>
>> scott
>>
>>
> 
> 
I dont think that that functionality is supported.  The CHANGES file is 
typically the best documentation for new/added functionality.  In this 
case, there are two references to what you are looking for:

The original:
> - There's now a "for" statement to iterate over the indices of a table
>   or the members of a set:
>                                                                                                           
>         for ( i in foo )
>                                                                                                           
>   for the above "foo" will iterate with i assigned to 1, 2, and 3; *but
>   not in general in that order*.
>                                                                                                           


and later:

> - Iterating over multi-dimensional tables/sets now works (Robin Sommer).
>   For example:
>                                                                                                           
>     const remote_peers_ssl : table[addr, port] of Peer &redef;
>     [...]
>     for ( [ip, p] in remote_peers_ssl )
>         connect_ssl(ip, p, remote_peers_ssl[ip, p]$retry);


This is not the first time that this has come up, but generic looping 
has been discouraged in general for performance reasons.  On the other 
hand if you want to add something... :-)

scott
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
Url : http://mailman.ICSI.Berkeley.EDU/pipermail/bro/attachments/20050921/0964a655/attachment.bin 


More information about the Bro mailing list