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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum
 Origin Forum
 problem with "while loop simulation"
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

mlhomer1

USA
2 Posts

Posted - 01/07/2002 :  2:49:41 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
I am very new to origin and labtalk. I am trying to read in some data files and search for a particular line. I have tried several ways to use the "while loop simulation", and every way seems to end up in an infinite loop. It's as if the program executes everything within the brackets of the for statement, without actually going back and evaluating expression2. All I want to do is stop at a line when the letter "h" is no longer found. Here is what I wrote:
for (ii=1; "%a" == "h"; ii++) { %a=%(jul1201la,1,ii); %a=;};
Alternately, I tried:
for (;"%a" != "n"; ) { %a= %(jul1201la,1,ii); ii++; };
Both end up in infinte loops. What am I doing wrong?
Thank you,
Margie

Mike Buess

USA
3037 Posts

Posted - 01/07/2002 :  4:31:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You need to put the break condition inside the brackets, not the parenthesis. The following script will test each cell in the first column of the active worksheet for the string 'h'. Note that it will stop on any string that is not identically 'h'. (It will stop on 'hh', 'gh', 'hi', etc.) It's more complicated if you're only looking for an arbitrary string that lacks the character 'h'.

for(ii=1;ii>0;ii++) {
%A=%(%H,1,ii); %A=;
if(%A!="h") break;
};

I hope that helps.

Mike Buess
Origin WebRing Member
Go to Top of Page

mlhomer1

USA
2 Posts

Posted - 01/07/2002 :  7:51:47 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mike, thank you, that worked.

I have a question, though. In the manual, it gives an example of what they call a "while loop simulation". It seems to imply that that within the for brackets, the script will be executed until the value of expression 2 changes. Their example works, but I couldn't get it to work any other way. Is there some trick to knowing when the expression is evaluated?
Go to Top of Page

CStorey

Canada
137 Posts

Posted - 01/10/2002 :  1:03:36 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The expression in the for loop is evaluated each time the loop is executed. The for loop will only evaluate an numerical expression, whereas a true WHILE loop may evaluate any condition. Thus in order to simulate a WHILE loop with a non-numerical end condition you need a combination or for and if expressions.

Hope this helps.
Craig

Craig Storey
Origin WebRing Member - http://g.webring.com/hub?ring=originwebring
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000