The efficient way to draw elements in a loop

I am new to OpenGL and trying to draw rectangles on the top of a texture.

is this the right way to draw? the output is right, but I am not sure of the efficiency of this method.

GLenum draw_rectangle(std::vector<DrawRectangle> rects , float line_width,  DrawColor drawCol = DrawColor(200.0, 0.0, 0.0))
{

	for (auto rect : rects) {
		glBegin(GL_LINE_LOOP);
		glLineWidth(line_width);
		glColor3f(drawCol.m_red, drawCol.m_green, drawCol.m_blue);
		glVertex3f(rect.m_x, rect.m_y, -1.0f);
		glVertex3f(rect.m_x + rect.m_width, rect.m_y, -1.0f);
		glVertex3f(rect.m_x + rect.m_width, rect.m_y + rect.m_height, -1.0f);
		glVertex3f(rect.m_x, rect.m_y + rect.m_height, -1.0f);
		glEnd();
	}
	
	return glGetError();
}