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
 if 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
amyz Posted - 06/03/2005 : 4:40:21 PM
For some reason, the following syntax doesn't execute the script in the first if(){}:

for(;;;){
if(){}
if(){}
else{}
}

Whereas the following does execute everything:

for(;;;){

if(){}

else{
if(){}
else{}
}

}

Any idea why? And is the 2nd method more time & memory-consuming than the first?

Thanks
3   L A T E S T    R E P L I E S    (Newest First)
greg Posted - 06/06/2005 : 10:55:24 AM
Your example has a syntax problem:

for(;;;){
if(){}
if(){}
else{}
}

Note the three semicolons in the for arguments.

Something in the correct form of

for(;;){
if(){}
if(){}
else{}
}

will work as demonstrated by this code :

for(done=0;done==0;){
if(1==1){type Hello}
if(1==2){type Hello2}
else{type Goodbye}
done=1;
}




amyz Posted - 06/03/2005 : 5:13:20 PM
Yes, I did have the semicolons, as indicated. The way it's written, I expected that, if the first if() condition is satisfied, the script would be executed, b/c the first if() is checked first...oh, I see, but it would not satisfy the second if() condition, hence would take on the value specified under else(). Alright, I guess my 2nd method is the only way then. Thanks!
Mike Buess Posted - 06/03/2005 : 5:01:38 PM
Are you using a semicolon after each statement? Your first script should look like this...

for(;;) {
if(){};
if(){};
else{};
};

...When written like that the first if statement executes as expected.

...Which raises the question: How do you expect it to execute? There are two separate if statements, the second has an else and the first does not. In your second script the second if is embedded in the first. The scripts naturally behave differently.

Mike Buess
Origin WebRing Member

Edited by - Mike Buess on 06/03/2005 5:04:24 PM

Edited by - Mike Buess on 06/03/2005 5:10:23 PM

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