Author |
Topic  |
|
mlhomer1
USA
2 Posts |
Posted - 01/07/2002 : 2:49:41 PM
|
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
|
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 |
 |
|
mlhomer1
USA
2 Posts |
Posted - 01/07/2002 : 7:51:47 PM
|
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? |
 |
|
CStorey
Canada
137 Posts |
Posted - 01/10/2002 : 1:03:36 PM
|
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 |
 |
|
|
Topic  |
|
|
|