Hello I need help with the following question Could you plea

Hello,

I need help with the following question. Could you please explain how you got your answer? Thank you in advance.

Given the following code, what is the final value of i? int ij; for i 0;i 4;i if(i 2) break; CO 5

Solution

Answer: 4

We have nested for loops here and we wwrite break statement inside second for loop.

for( j=0; j<3; j++){
if(i==2)
break;

}

So break statement will not applicable for first for loop. so when i value is 2 , break statement will execute and break the second for loop so first for loop will continue to iterate until i value reaches 4. when i value is 4 in first for loop i < 4 condition will return false. so first for loop will terminate when i value is 4.

So after for loop termination, i value becomes 4.

Hello, I need help with the following question. Could you please explain how you got your answer? Thank you in advance. Given the following code, what is the fi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site