for loop

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

bchen@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@lbl.gov>:

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@bro-ids.org
mailman.icsi.berkeley.edu Mailing Lists

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... :slight_smile:

scott