From comments, it seems that you want to apply a categorized renderer. A loop like yours is not necessary (unless there are other needs that you haven't explained in your original question).
You may use the following code as a reference (adapt it to your specific case):
from qgis.core import *
from PyQt4.QtGui import QColor
layer = iface.activeLayer() # load the layer as you want
# define the lookup >> value : (color, label)
colors = {1: ('red', 'some_text_for_red'), 2: ('yellow', 'some_text_for_yellow'), 3: ('cyan', 'some_text_for_cyan'), 4: ('green', 'some_text_for_green'), 5: ('blue', 'some_text_for_blue'), 6: ('magenta', 'some_text_for_magenta'), 7: ('grey', 'some_text_for_grey')}
# create a category for each item in your layer
categories = []
for value, (color, label) in colors.items():
symbol = QgsSymbolV2.defaultSymbol(layer.geometryType())
symbol.setColor(QColor(color))
category = QgsRendererCategoryV2(value, symbol, label)
categories.append(category)
# create the renderer and assign it to the layer
expression = 'my_field' # field name
renderer = QgsCategorizedSymbolRendererV2(expression, categories)
renderer = QgsCategorizedSymbolRendererV2(expression, categories)
layer.setRendererV2(renderer)
layer.triggerRepaint()
It will return something like this: