Determine which are infite loops and why:
a. int i = 0;
while(i<6){
i = i * i;
}
b. int i = 0;
while(i<6){
i--;
}
c. int i = 10,000;
while(i>=6){
i--;
}
d. int i = 1; while(i<6){
i = i * 2;
}
e. int i = 75; while(i>5){
i = i / 5;
a and b are the infinite loops
a loop prints zeros because i is the values which gives same output as answer so loop does not get the where to stop .
ex.i = i * i always gives i let i=0 or i=1 both number gives always answer as o and 1 as final output so it will goes to infinite.
b loop is i - -; ( Decremented ) infinite and if loop is incremented then it will goes to 1 to 6 because loop i<6(ie. 0 < 6) but in case of our loop it will moves goes infinite
c loop prints 10000 to 5 numbers
d loop prints 2 4 8
e loop prints 15 and 3
Get Answers For Free
Most questions answered within 1 hours.