0
Where did I done wrong
It is showing error ,but how ? I made it correct https://code.sololearn.com/ccG53SwbOZM1/?ref=app
2 Respuestas
+ 4
Actully in your case your second loop which u used it woRkiNg infinite time becoz you
Written
for (int i=1;true;i++) here all times condition will be true so woRkiNg infinite times . Please write correct condition
Like
i<size or Number of times how many times u want to execute your loop .
inside “if” statement if you write statements after break statement, then the statements which are written below “break” keyword will never execute because if the condition is false, then the loop will never execute. And if the condition is true, then due to “break” it will never execute, since “break” takes the flow of execution outside the “if” statement.
You can read more about when this error occur.
https://www.geeksforgeeks.org/unreachable-code-error-in-java/amp/
+ 1
The break statement breaks loop 2, not loop 1. Since loop 1's condition is always true it will never stop. Hence why System.out.print(); is unreachable.
for(int i=1;true;i++){//Loop 1
for(int j=0;j<size;j++){//Loop 2
if(i!=A[j]){
temp=i;
break;
}
}
}
System.out.print(temp);