I don't think you can do exactly what you want. But there are a few options that come close.
If you don't want the source block included in your output, you can do this with the following block:
#+begin_src bash :exports results :results verbatim
for i in 1 2 3
do
echo hello number $i
done
#+end_src
This will generate:
#+RESULTS:
: hello number 1
: hello number 2
: hello number 3
This uses a bash script, but you can use any language you like. Setting :exports results
in the header suppresses the source block from your export. Depending on your intent, you may also want to use :results output raw
, or otherwise configure the presentation of the resulting text.
You can't put the loop in the header, but you can assign the variables there:
#+begin_src bash :results verbatim :var vals="1 2 3"
for i in $vals
do
echo hello number $i
done
#+end_src
Another approach is to use noweb syntax. In this case, you define the code block you want to insert, here named 'loop', and then you refer to it at the location you want it to appear. This would allow you to reuse the same structure with different values throughout your document:
#+name: loop
#+begin_src bash :exports none :results raw :var vals="1 2 3"
for i in $vals
do
echo hello number $i
done
#+end_src
#+begin_src text :noweb yes
<<loop(vals="1 2 3")>>
#+end_src
#+begin_src text :noweb yes
<<loop(vals="a b c")>>
#+end_src
#+begin_src text :noweb yes
<<loop(vals="apple orange banana")>>
#+end_src
This generates the following pdf:
For more details, see the org mode manual, Working with Source Code, NoWeb Reference Syntax,
hello number
version? If the first, why can't you loop inside the block e.g with ashell
source block and a shellfor
loop?