# Loops

> So far we have introduced a couple of EBNF operators that deal with looping. We have the (+) positive operator, which matches the preceding symbol one (1) or more times, as well as the Kleene star (*) which matches the preceding symbol zero (0) or more times.

> If we look more closely, take note that we generalized the optional expression of the form !a above in the same category as loops. This is logical, considering that the optional matches the expression following it zero (0) or (1) time. Taking this further, we may want to have a generalized loop operator. To some this may seem to be a case of overkill. Yet there are grammars that are impractical and cumbersome, if not impossible, for the basic EBNF iteration syntax to specify. Examples:

> > A file name may have a maximum of 255 characters only.
> > A specific bitmap file format has exactly 4096 RGB color information.
> > A 32 bit binary string (1..32 1s or 0s).

> Other than the Kleene star (*), the Positive closure (+), and the optional (!), a more flexible mechanism for looping is provided for by the framework. The following are availabe on all parsers.

> > Loop Constructs
> > a.repeat(); | Repeat a, zero or more times Same as a.repeat(0, more); and *a;
> > a.repeat(n); a(n); | Repeat a, exactly n times
> > a.repeat(n1, n2); a(n, to); | Repeat a, at least n1 times and at most n2 times
> > a.repeat(n, more); a(n, more); | Repeat a, n or more times

#