protected function compileWhile(Node $node)
    {

        $subject = $node->subject;

        if ($this->isVariable($subject))
            $subject = "isset({$subject}) ? {$subject} : null";

        $hasChildren = count($node->children) > 0;
        $isDoWhile = $node->prev() && $node->prev()->type === 'do';

        if (!$hasChildren && !$isDoWhile)
            $this->throwException(
                'A while-loop without children you loop through is not valid if'
                .' there\'s no do-statement before it.',
                $node
            );
        else if ($isDoWhile && $hasChildren)
            $this->throwException(
                'In a do-while statement the while-part shouldn\'t have any children. Put the children in the `do`-part',
                $node
            );

        $phtml = $this->createCode("while ({$subject})".($hasChildren ? ' {' : ''), $isDoWhile ? ' ' : '<?php ').$this->newLine();

        if ($hasChildren) {

            $phtml .= $this->compileChildren($node->children).$this->newLine();
            $phtml .= $this->indent().$this->createCode('}').$this->newLine();
        }

        return $phtml;
    }