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	Sun Nov 16 19:21:13 2008
@@ -832,10 +832,30 @@
 
     if (++eval_depth > 4)
 	int_error(save_token, "Deep recursion in evaluate");
+/* shige */
+#if 0
     if (!(command = try_to_get_string()))
 	int_error(c_token, "Expected command string");
 
     do_string(command, TRUE);
+#else
+#if 0
+    fprintf(stderr,"DEBUG: 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 0
+	fprintf(stderr,"DEBUG: command=[%s]\n",command);
+#endif
+	do_string(command, TRUE);
+	if (next_iteration())
+	  c_token = save_token;
+	else break;
+    }
+#endif
     --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	Sun Nov 16 19:21:40 2008
@@ -54,11 +54,22 @@
 int at_highest_column_used = -1;
 
 /* These are used by the iterate-over-plot code */
+/* shige */
+#if 0
 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;
+#else
+#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;
+#endif
 int iteration = 0;
 
 /* Internal prototypes: */
@@ -893,15 +904,38 @@
 {
     char *errormsg = "Expecting iterator \tfor [<var> = <start> : <end>]\n\t\t\tor\tfor [<var> in \"string of words\"]";
 
+/* shige */
+#if 0
     iteration_udv = NULL;
     free(iteration_string);
     iteration_string = NULL;
     iteration_increment = 1;
     iteration = 0;
+#endif
 
     if (!equals(c_token, "for"))
 	return;
+/* shige */
+#if 1
+    if(++iteration_level>=ITR_MAX_LEVEL) {
+	iteration_level=-1;
+	int_error(c_token, "Too deep iteration nest.");
+    }
+#if 0
+    fprintf(stderr,"DEBUG: 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;
+#endif
+
+/* shige */
+#if 0
     c_token++;
     if (!equals(c_token++, "[") || !isletter(c_token))
 	int_error(c_token-1, errormsg);
@@ -945,6 +979,66 @@
  	int_error(c_token-1, errormsg);
 
     iteration_current = iteration_start;
+#else
+    c_token++;
+    if (!equals(c_token++, "[") || !isletter(c_token)) {
+	iteration_level=-1;
+	int_error(c_token-1, errormsg);
+    }
+    iteration_udv[iteration_level] = add_udv(c_token++);
+
+    if (equals(c_token, "=")) {
+	c_token++;
+	iteration_start[iteration_level] = int_expression();
+	if (!equals(c_token++, ":")) {
+	    iteration_level=-1;
+	    int_error(c_token-1, errormsg);
+	}
+	iteration_end[iteration_level] = int_expression();
+	if (equals(c_token,":")) {
+	    c_token++;
+	    iteration_increment[iteration_level] = int_expression();
+	    if (iteration_increment[iteration_level] <= 0)
+		iteration_increment[iteration_level] = 1;
+	}
+	if (!equals(c_token++, "]")) {
+	    iteration_level=-1;
+	    int_error(c_token-1, errormsg);
+	}
+	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[iteration_level] = try_to_get_string();
+	if (!iteration_string[iteration_level]) {
+	    iteration_level=-1;
+	    int_error(c_token-1, errormsg);
+	}
+	if (!equals(c_token++, "]")) {
+	    iteration_level=-1;
+	    int_error(c_token-1, errormsg);
+	}
+	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"] */
+	iteration_level=-1;
+ 	int_error(c_token-1, errormsg);
+    }
+
+    iteration_current[iteration_level] = iteration_start[iteration_level];
+#endif
 
 }
 
@@ -954,6 +1048,8 @@
 TBOOLEAN
 next_iteration()
 {
+/* shige */
+#if 0
     if (!iteration_udv) {
 	iteration = 0;
 	return FALSE;
@@ -966,14 +1062,44 @@
     } else
 	iteration_udv->udv_value.v.int_val = iteration_current;
     return (iteration_current <= iteration_end);
+#else
+    if (iteration_level < 0 || !iteration_udv[iteration_level]) {
+	iteration = 0;
+	return FALSE;
+    }
+    iteration++;
+    iteration_current[iteration_level] += iteration_increment[iteration_level];
+    if (iteration_string[iteration_level]) {
+	free(iteration_udv[iteration_level]->udv_value.v.string_val);
+	iteration_udv[iteration_level]->udv_value.v.string_val 
+	    = gp_word(iteration_string[iteration_level],
+		      iteration_current[iteration_level]);
+    } else
+	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;
+    }
+    return (iteration_current <= iteration_end);
+#endif
 }
 
 TBOOLEAN
 empty_iteration()
 {
+/* shige */
+#if 0
     if (iteration_udv
         && (iteration_start > iteration_end))
         return TRUE;
+#else
+    if (iteration_level>=0 && iteration_udv[iteration_level]
+        && (iteration_start[iteration_level] > iteration_end[iteration_level]))
+        return TRUE;
+#endif
     else
         return FALSE;
 }
