You are not logged in.

1

Thursday, June 2nd 2011, 2:10pm

Why not also "foreach"

Hi there

I've implemented a "foreach" function which allows you to iterate, for instance, over all hotspots, plugins, or elements in an XML structure.

Since the new prerelase has the fantastic "for" and "loop", why not also a "foreach"? I've found it very useful on my projects.

Here's my implementation and a test case:
<!-- %1 - what to iterate
%2 - iterator variable
%3 - variable where iterated structure will be stored
%4 - action -->
<action name="foreach">
set(%2,0);
loop(%1[get(%2)] !== null,
copy(%3, %1[get(%2)]);
%4;
inc(%2);
);
</action>



<teststruct>
<thumb name="hello" someproperty="this"/>
<thumb name="foo" someproperty="is a"/>
<thumb name="bar" someproperty="test"/>
</teststruct>

<action name="test-foreach">
foreach(teststruct.thumb,tmpvar,loopedstruct,
trace(tmpvar);
trace(loopedstruct.name);
trace(loopedstruct.someproperty);
)
</action>
PanoTag: Facebook tagging for krpano

KRPano development and more: http://www.digisfera.pt/en/development

2

Saturday, June 4th 2011, 1:27pm

Oops, just realized this is the tools forum. Couldn't find any way to move the post to the correct one.
PanoTag: Facebook tagging for krpano

KRPano development and more: http://www.digisfera.pt/en/development

3

Tuesday, June 7th 2011, 10:09pm

Hi,
Oops, just realized this is the tools forum. Couldn't find any way to move the post to the correct one.
no problem, I have moved the thread now

about:

Quoted

Why not also "foreach"
there is no special reason, I will think about it, thanks!

best regards,
Klaus