# View Helper - Cycle
The `Cycle` helper is used to alternate a set of values.
## Basic Usage
To add elements to cycle, specify them in constructor:
```php
books as $book): ?>
= $this->escapeHtml($book['author']) ?> |
```
The output:
```php
```
Instead of passing the data at invocation, you can assign it ahead of time:
```php
cycle()->assign(['#F0F0F0', '#FFF'])); ?>
```
You can also cycle in reverse, using the `prev()` method instead of `next()`:
```php
books as $book): ?>
escapeHtml($book['author']) ?> |
```
The output of the two previous examples combined becomes:
```php
```
## Working with two or more cycles
If you are nesting cycles, you must provide all but one of them with a name; do
this by providing a second parameter to the `cycle()` invocation:
`$this->cycle(array('#F0F0F0', '#FFF'), 'cycle2')`
```php
books as $book): ?>
= $this->cycle([1, 2, 3], 'number')->next() ?> |
= $this->escapeHtml($book['author']) ?> |
```
You can also provide a `$name` argument to `assign()`:
```php
cycle()->assign([1, 2, 3], 'number'); ?>
```
Or use the `setName()` method priort to invoking either of `next()` or `prev()`.
As a combined example:
```php
cycle()->assign(['#F0F0F0', '#FFF'], 'colors');
$this->cycle()->assign([1, 2, 3], 'numbers');
?>
books as $book): ?>
= $this->cycle()->setName('numbers')->next() ?> |
= $this->escapeHtml($book['author']) ?> |
```