English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

for(intMyCount = 1; intMyCount <= 15; intMyCount++)
{
alert("Hello World!");
}//end for

What is the value of intMyCount when the code finishes?
15 or 16?

2007-12-09 09:55:35 · 1 answers · asked by Anonymous in Computers & Internet Programming & Design

for(j = 1; j <= 4; j++)
{
for(k = 1; k <=7; k++)
{
intMyCount++;
}
}

What is the value of intMyCount when the code finishes? Is it 7 because it's inside the for loop of k?

2007-12-09 09:58:31 · update #1

1 answers

16. When intMyCount is 15, the conditional will evaluate to true, the loop will complete, and intMyCount will be incremented to 16. On the next iteration, the conditional will fail and control will pass to the next statement after the for loop.

Assuming intMyCount is 0 before the nested loops, it will be 28 when the outer loop completes. The outer loop runs 4 times, and the inner loop runs 7 times for *each* outer loop.

2007-12-09 10:17:30 · answer #1 · answered by daa 7 · 0 0

fedest.com, questions and answers