/*
 * RepeatStatement.cpp
 *
 *  Created on: Dec 9, 2012
 *      Author: attero
 */

#include "RepeatStatement.h"

RepeatStatement::RepeatStatement()
{
	how_many_times = 0;
	body = NULL;
	this->type = "RepeatStatement";
}

RepeatStatement::~RepeatStatement()
{
	delete body;
}


void RepeatStatement::add_body(ASTStatement * statement)
{
	body = statement;
}

SenchaObject RepeatStatement::execute()
{
	for(int i = 0; i < how_many_times; i++)
		{
			if(i == how_many_times - 1) return body->execute();
			else body->execute();
		}
	return SenchaObject();
}



void RepeatStatement::add_iteration_number(SenchaObject so)
{
	if(so.type == SenchaObject::integer_number)
	{
		how_many_times = so.integer;
	}
	else
	{
		how_many_times = 0;
	}
}
