diff -u gnuplot-current/src/command.c.ORG gnuplot-current/src/command.c
--- gnuplot-current/src/command.c.ORG	Fri Oct 31 17:49:51 2008
+++ gnuplot-current/src/command.c	Tue Nov 18 13:10:24 2008
@@ -832,10 +832,23 @@
 
     if (++eval_depth > 4)
 	int_error(save_token, "Deep recursion in evaluate");
-    if (!(command = try_to_get_string()))
-	int_error(c_token, "Expected command string");
-
-    do_string(command, TRUE);
+#if DEBUG1
+    fprintf(stderr,"DEBUG1: eval_depth=%d\n",eval_depth);
+#endif
+    check_for_iteration();
+    save_token = c_token;
+    while (TRUE) {
+	if (!(command = try_to_get_string()))
+	    int_error(c_token, "Expected command string");
+#if DEBUG1
+	fprintf(stderr,"DEBUG1: command=[%s]\n",command);
+#endif
+	do_string(command, TRUE);
+	if (next_iteration())
+	    c_token = save_token;
+	else
+	    break;
+    }
     --eval_depth;
 }
 
diff -u gnuplot-current/src/parse.c.ORG gnuplot-current/src/parse.c
--- gnuplot-current/src/parse.c.ORG	Fri Oct 31 17:49:53 2008
+++ gnuplot-current/src/parse.c	Tue Nov 18 13:10:13 2008
@@ -54,11 +54,13 @@
 int at_highest_column_used = -1;
 
 /* These are used by the iterate-over-plot code */
-static struct udvt_entry *iteration_udv = NULL;
-static int iteration_start = 0, iteration_end = 0;
-static int iteration_increment = 1;
-static int iteration_current = 0;
-static char *iteration_string = NULL;
+#define ITR_MAX_LEVEL 3
+static struct udvt_entry *iteration_udv[ITR_MAX_LEVEL];
+static int iteration_start[ITR_MAX_LEVEL], iteration_end[ITR_MAX_LEVEL];
+static int iteration_increment[ITR_MAX_LEVEL];
+static int iteration_current[ITR_MAX_LEVEL];
+static char *iteration_string[ITR_MAX_LEVEL];
+static int iteration_level=-1;
 int iteration = 0;
 
 /* Internal prototypes: */
@@ -893,58 +895,68 @@
 {
     char *errormsg = "Expecting iterator \tfor [<var> = <start> : <end>]\n\t\t\tor\tfor [<var> in \"string of words\"]";
 
-    iteration_udv = NULL;
-    free(iteration_string);
-    iteration_string = NULL;
-    iteration_increment = 1;
-    iteration = 0;
 
     if (!equals(c_token, "for"))
 	return;
+    if (++iteration_level >= ITR_MAX_LEVEL)
+	int_error(c_token, "Too deep iteration nest.");
+#if DEBUG1
+    fprintf(stderr,"DEBUG1: level=%d\n",iteration_level);
+#endif
+    iteration_udv[iteration_level] = NULL;
+    free(iteration_string[iteration_level]);
+    iteration_string[iteration_level] = NULL;
+    iteration_increment[iteration_level] = 1;
+    iteration_start[iteration_level] = iteration_end[iteration_level] = 0;
+    iteration_current[iteration_level] = 0;
+    iteration = 0;
 
     c_token++;
     if (!equals(c_token++, "[") || !isletter(c_token))
 	int_error(c_token-1, errormsg);
-    iteration_udv = add_udv(c_token++);
+    iteration_udv[iteration_level] = add_udv(c_token++);
 
     if (equals(c_token, "=")) {
 	c_token++;
-	iteration_start = int_expression();
+	iteration_start[iteration_level] = int_expression();
 	if (!equals(c_token++, ":"))
 	    int_error(c_token-1, errormsg);
-	iteration_end = int_expression();
+	iteration_end[iteration_level] = int_expression();
 	if (equals(c_token,":")) {
 	    c_token++;
-	    iteration_increment = int_expression();
-	    if (iteration_increment <= 0)
-		iteration_increment = 1;
+	    iteration_increment[iteration_level] = int_expression();
+	    if (iteration_increment[iteration_level] <= 0)
+		iteration_increment[iteration_level] = 1;
 	}
 	if (!equals(c_token++, "]"))
 	    int_error(c_token-1, errormsg);
-	if (iteration_udv->udv_undef == FALSE)
-	    gpfree_string(&iteration_udv->udv_value);
-	Ginteger(&(iteration_udv->udv_value), iteration_start);
-	iteration_udv->udv_undef = FALSE;
+	if (iteration_udv[iteration_level]->udv_undef == FALSE)
+	    gpfree_string(&iteration_udv[iteration_level]->udv_value);
+	Ginteger(&(iteration_udv[iteration_level]->udv_value), 
+		 iteration_start[iteration_level]);
+	iteration_udv[iteration_level]->udv_undef = FALSE;
     }
 
     else if (equals(c_token++, "in")) {
-	iteration_string = try_to_get_string();
-	if (!iteration_string)
+	iteration_string[iteration_level] = try_to_get_string();
+	if (!iteration_string[iteration_level])
 	    int_error(c_token-1, errormsg);
 	if (!equals(c_token++, "]"))
 	    int_error(c_token-1, errormsg);
-	iteration_start = 1;
-	iteration_end = gp_words(iteration_string);
-	if (iteration_udv->udv_undef == FALSE)
-	    gpfree_string(&iteration_udv->udv_value);
-	Gstring(&(iteration_udv->udv_value), gp_word(iteration_string, 1));
-	iteration_udv->udv_undef = FALSE;
+	iteration_start[iteration_level] = 1;
+	iteration_end[iteration_level] 
+	    = gp_words(iteration_string[iteration_level]);
+	if (iteration_udv[iteration_level]->udv_undef == FALSE)
+	    gpfree_string(&iteration_udv[iteration_level]->udv_value);
+	Gstring(&(iteration_udv[iteration_level]->udv_value), 
+		gp_word(iteration_string[iteration_level], 1));
+	iteration_udv[iteration_level]->udv_undef = FALSE;
     }
 
     else /* Neither [i=B:E] or [s in "foo"] */
  	int_error(c_token-1, errormsg);
 
-    iteration_current = iteration_start;
+    iteration_current[iteration_level] = iteration_start[iteration_level];
 
 }
 
@@ -954,26 +966,44 @@
 TBOOLEAN
 next_iteration()
 {
-    if (!iteration_udv) {
+    if (iteration_level < 0 || !iteration_udv[iteration_level]) {
 	iteration = 0;
 	return FALSE;
     }
     iteration++;
-    iteration_current += iteration_increment;
-    if (iteration_string) {
-	free(iteration_udv->udv_value.v.string_val);
-	iteration_udv->udv_value.v.string_val = gp_word(iteration_string,iteration_current);
+    iteration_current[iteration_level] += iteration_increment[iteration_level];
+    if (iteration_string[iteration_level]) {
+	gpfree_string(&(iteration_udv[iteration_level]->udv_value));
+	Gstring(&(iteration_udv[iteration_level]->udv_value), 
+		gp_word(iteration_string[iteration_level],
+			iteration_current[iteration_level]));
     } else
-	iteration_udv->udv_value.v.int_val = iteration_current;
-    return (iteration_current <= iteration_end);
+	iteration_udv[iteration_level]->udv_value.v.int_val 
+	    = iteration_current[iteration_level];
+    if (iteration_current[iteration_level] <= iteration_end[iteration_level])
+	return 1;
+    else {
+	iteration_level--;
+	return 0;
+    }
 }
 
 TBOOLEAN
 empty_iteration()
 {
-    if (iteration_udv
-        && (iteration_start > iteration_end))
+    if (iteration_level>=0 && iteration_udv[iteration_level]
+        && (iteration_start[iteration_level] > iteration_end[iteration_level]))
         return TRUE;
     else
         return FALSE;
+}
+
+void
+reset_iteration()
+{
+    while (iteration_level >= 0) {
+       free(iteration_string[iteration_level]);
+       iteration_string[iteration_level] = NULL;
+       iteration_level--;
+    }
 }
diff -u gnuplot-current/src/parse.h.ORG gnuplot-current/src/parse.h
--- gnuplot-current/src/parse.h.ORG	Fri Oct 31 17:49:53 2008
+++ gnuplot-current/src/parse.h	Tue Nov 18 12:47:10 2008
@@ -74,6 +74,7 @@
 void check_for_iteration __PROTO((void));
 TBOOLEAN next_iteration  __PROTO((void));
 TBOOLEAN empty_iteration  __PROTO((void));
+void reset_iteration __PROTO((void));
 
 /* Some commands, e.g. set xtics, need to know if this is the first time
  * or a subsequent time through the iteration.  Export a counter.
diff -u gnuplot-current/src/plot.c.ORG gnuplot-current/src/plot.c
--- gnuplot-current/src/plot.c.ORG	Fri Oct 31 17:49:54 2008
+++ gnuplot-current/src/plot.c	Tue Nov 18 13:03:59 2008
@@ -575,6 +575,7 @@
 #endif
 	load_file_error();	/* if we were in load_file(), cleanup */
 	reset_eval_depth();     /* reset evaluate command recursion counter */
+	reset_iteration();      /* reset iteration recursion counter */
 	SET_CURSOR_ARROW;
 
 #ifdef VMS
