Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ethan A Merritt Newsgroups: comp.graphics.apps.gnuplot Subject: Re: Question about "sprintf" "@" "do for" Date: Tue, 02 Feb 2016 16:05:25 -0800 Organization: gnuplot development Lines: 44 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit Injection-Date: Wed, 3 Feb 2016 00:02:37 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="8e86a57dfa599721f116da4577f3d1af"; logging-data="9020"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NstWZt4WxgHs3A/j+kDIf" User-Agent: KNode/4.10.5 Cancel-Lock: sha1:wRXSc6HpEZ96Q8ik3V/03TJLwQw= Xref: csiph.com comp.graphics.apps.gnuplot:3204 Jörg Buchholz wrote: > Hello, > > this works: > > A1=1 > A2=2 > A3=3 > > i=1 > vari=sprintf("A%.f",i) > print vari,"=",@vari > i=i+1 > vari=sprintf("A%.f",i) > print vari,"=",@vari > i=i+1 > vari=sprintf("A%.f",i) > print vari,"=",@vari > > do for [i=1:3]{ > vari=sprintf("A%.f",i) > print vari > } > > But I want to have "print vari,"=",@vari" in the loop. But it dosen't > work. Why can't I use "print vari,"=",@vari" in the loop? The @ indicates macro expansion, which only happens once. And that one time is before the loop is executed. So whatever value @vari has at the start of loop execution, that is the value it will have every time through. > Is there a solution for? You don't need macros for this do for [i=1:3] { vari = print vari, ' = ', value(vari) } > Jörg