| 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 |