# ATSLIB/prelude/intrange

• intrange_foreach
• intrange_foreach_env
• intrange_foreach\$cont
• intrange_foreach\$fwork
• intrange_rforeach
• intrange_rforeach_env
• intrange_rforeach\$cont
• intrange_rforeach\$fwork

• ## intrange_foreach

### Synopsis

```fun{}
intrange_foreach (l: int, r: int): int```

### Description

Given two integers l and r, this function enumerates the integers between l and r-1, inclusive, and then applies to each enumerated integer the function implemented by intrange_foreach\$fwork. The enumeration process stops if the function implemented by intrange_foreach\$cont returns false, and the integer value returned by intrange_foreach indicates the point of the stoppage.

## intrange_foreach_env

### Synopsis

```fun{env:vt0p}
intrange_foreach_env (l: int, r: int, env: &(env) >> _): int```

### Description

This function does essentially the same as intrange_foreach except for taking an additional argument that serves as an environment.

### Example

The following code implements a function for constructing a list of randomly generated values:
```//
//
fun{a:t@ype}
list_randgen
(n: int): List0_vt (a) = let
//
viewtypedef env = List0_vt (a)
//
implement
intrange_foreach\$fwork<env>
(_, env) = env := list_vt_cons (\$R.randgen_val<a> (), env)
// end of [intrange_foreach\$fwork]
//
var res: env = list_vt_nil ()
val _(*n*) = intrange_foreach_env<env> (0, n, res)
//
in
res
end // end of [list_randgen]
```

## intrange_foreach\$cont

### Synopsis

```fun{env:vt0p}
intrange_foreach\$cont (i: int, env: &env): bool```

### Description

The default implementation of this function always returns true.

## intrange_foreach\$fwork

### Synopsis

```fun{env:vt0p}
intrange_foreach\$fwork (i: int, env: &(env) >> _): void```

### Description

By default, this function is unimplemented.

## intrange_rforeach

### Synopsis

```fun{}
intrange_rforeach (l: int, r: int): int```

### Description

Given two integers l and r, this function enumerates in the reverse order the integers between l and r-1, inclusive, and then applies to each enumerated integer the function implemented by intrange_rforeach\$fwork. The enumeration process stops if the function implemented by intrange_rforeach\$cont returns false, and the integer value returned by intrange_rforeach indicates the point of stoppage.

## intrange_rforeach_env

### Synopsis

```fun{env:vt0p}
intrange_rforeach_env (l: int, r: int, env: &(env) >> _): int```

### Description

This function does essentially the same as intrange_rforeach except for taking an additional argument that serves as an environment.

## intrange_rforeach\$cont

### Synopsis

```fun{env:vt0p}
intrange_rforeach\$cont (i: int, env: &env): bool```

### Description

The default implementation of this function always returns true.

## intrange_rforeach\$fwork

### Synopsis

```fun{env:vt0p}
intrange_rforeach\$fwork (i: int, env: &(env) >> _): void```

### Description

By default, this function is unimplemented.
 This page is created with ATS by Hongwei Xi and also maintained by Hongwei Xi.