PDA

View Full Version : can there be more than one "condition" in a for loop?


Gladstone
12-09-2002, 08:58 PM
like this:

for(i=0; i=j || i=k; i++){
some code here;}

I know that one can have multiple conditions in a while loop but have never seen it in a for loop. Can it be done?

tia,
Gladstone

Gladstone
12-09-2002, 09:39 PM
I seem to have answered my own question. :)

with this, the loop stops when i is equal to 1 because j equals k!

<html>
<head>
<script language=javascript>
var j=3;
var k=1;
for(var i=0; (i<=7)&&(j!=k); i++){
k++;
alert("i = " + i);
}
</script>
</head>
<body>
</body>
</html>

Gladstone

p.s. this seems like an alternative to using break in an if statement to break out of the loop. yes?