# Cycle Helper

The `Cycle` helper is used to alternate a set of values.

## Cycle Helper Basic Usage

To add elements to cycle just specify them in constructor or use `assign(array $data)` function

    <?php foreach ($this->books as $book):?>
      <tr style="background-color:<?php echo $this->cycle(array("#F0F0F0",
                                                                "#FFFFFF"))
                                                  ->next()?>">
      <td><?php echo $this->escape($book['author']) ?></td>
    </tr>
    <?php endforeach;?>

    // Moving in backwards order and assign function
    $this->cycle()->assign(array("#F0F0F0","#FFFFFF"));
    $this->cycle()->prev();
    ?>

The output

    <tr style="background-color:'#F0F0F0'">
       <td>First</td>
    </tr>
    <tr style="background-color:'#FFFFFF'">
       <td>Second</td>
    </tr>

## Working with two or more cycles

To use two cycles you have to specify the names of cycles. Just set second parameter in cycle method. `$this->cycle(array("#F0F0F0","#FFFFFF"),'cycle2')`. You can also use setName($name) function.

    <?php foreach ($this->books as $book):?>
      <tr style="background-color:<?php echo $this->cycle(array("#F0F0F0",
                                                                "#FFFFFF"))
                                                  ->next()?>">
      <td><?php echo $this->cycle(array(1,2,3),'number')->next()?></td>
      <td><?php echo $this->escape($book['author'])?></td>
    </tr>
    <?php endforeach;?>