The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Switch inside a for loop

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
srmcarneir Posted - 07/08/2004 : 08:20:31 AM
Hi All,

We have a LabTalk script which contains a block as follows:
...


for (aa = 1; aa <= iNum; aa++ )
{
ierrGeg = fdlog.get(A, aa);

if ( ierrGet == 1 )
run.section(,ChooseCondition, aa);
}

[ChooseCondition]

switch (%1)
{
case 1:
...some calculations...
break;

default:
...other calculations...
break;
}

return 0;


We have noticed that the for loop stopped after
having run for aa = 1, even when iNum > 1.
It seems that the "break" command makes an exit
out of the switch command, by exiting the for
loop also. We have not found a way to let
the for loop continue running until aa <= iNum (when iNum >1) yet.
We also have tried the command continue, unsuccessfully.

Best Regards,

Ricardo Carneiro
3   L A T E S T    R E P L I E S    (Newest First)
Mike Buess Posted - 07/08/2004 : 2:19:46 PM
Hi Ricardo,

I tried this simplied version of your script...

for(aa=1; aa<iNum; aa++)
{
run.section(,ChooseCondition,aa);
};

[ChooseCondition]
switch(%1)
{
case 1: ty 0; break;
default: ty $(%1); break;
};

It works fine unless iNum is undefined. I'd look closely at the calculations in the switch statement and make sure they don't change the value of either iNum or aa. An advantage or disadvantage (depending on your viewpoint) of LabTalk over Origin C is that LabTalk variables are global. Changing the value of aa in the switch command will effect the for loop which calls it. In fact, it's not necessary to pass aa as an argument - run.section(,ChooseCondition,aa). This will work just as well...

for (aa=1; aa<=iNum; aa++)
{
run.section(,ChooseCondition);
}

[ChooseCondition]
switch(aa)
{
}

Mike Buess
Origin WebRing Member
srmcarneir Posted - 07/08/2004 : 1:08:25 PM
Hi Mike, All,

Thanks for your prompt response!

I apologize for that , it is really a misspelling.
Please consider ierrGet in all cases instead of
ierrGeg.
I wish this mistake was made in the original script of mine,
that would make things much easier.

By the way, we are planning to redesign our script
from scratch because this has already taken too
long to debug. We are also considering the "translation"
of some LabTalk blocks to OriginC.

[Just forgot to inform: we are using OriginPro 7 with SR4 under
Win2k. Sorry for that!]

We appreciate your help!

Regards,

Ricardo Carneiro
Mike Buess Posted - 07/08/2004 : 10:23:01 AM
Hi Ricardo,

This might just be a typo in your post but it's best to eliminate the obvious first...

You define ierrGeg=fdlog.get(A,aa) but use if(ierrGet==1) as the condition. If that's really in your script then ierrGet is always undefined and your script will fail.

Mike Buess
Origin WebRing Member

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000