In this question, it was mentioned that one can output the concatenation of a string and a variable by using StringForm[]:
var1 = "Tree";
var2 = 10;
StringForm["The `1` is about `2` feet tall...", var1, var2]
(* "The Tree is about 10 feet tall..." *)
This works. However, when I try to use it within a loop, I get no output whatsoever:
For[i = 1, i < 10, i++,
(
var1 = "Tree";
var2 = 10;
StringForm["The `1` is about `2` feet tall...", var1, var2]
)]
I don't understand why there is no output here as I am just repeating the same operation $i$ times. What am I missing?
EDIT: The aim is to perform a task within the For loop, and print some intermediary results every $n$ iterations.
Table.Fordoes not return anything. – Kuba Oct 26 '18 at 12:45Printor for the latter caseSow/Reap. At the end you can haveTableto manage your loop andTable[proc; string, {i, 10}]or something. Assuming string generation is the last step only. – Kuba Oct 26 '18 at 12:48Table. In the meantime, can you please explain why a perfectly valid output does not output when placed within aForloop? As a software developer, this makes no sense to me. – Klangen Oct 26 '18 at 12:56Forevaluates expression in a loop but does not return anything. Here's more about that: https://mathematica.stackexchange.com/a/124077/5478 – Kuba Oct 26 '18 at 13:00