I was doing couple of example from the book.
I am not able to get it right please help.
I have exam tomm.
9. Which of the following code blocks produces an infinite loop? Assume num has been initialized to 15.
Answer
a. for(i=5; i >=0; i++){
sum += i;
}
b. while(num > 0){
i++;
}
c. while(num > 0){
i--;
}
d. all of these
Last edited on
Do you understand why D is the correct answer?
Simply knowing that D is the correct answer won't help with your exam since it's unlikely that exact problem will be on the exam.
uhhhh. What is sum?
b and c loop for sure.
a should only loop 5 times. You have to tell us what sum is.
[EDIT]
Never mind, just read i=5
Last edited on