0

Where did I done wrong

It is showing error ,but how ? I made it correct https://code.sololearn.com/ccG53SwbOZM1/?ref=app

3rd Oct 2020, 6:20 AM
Bharadwaj
Bharadwaj - avatar
2 Answers
+ 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/
3rd Oct 2020, 6:42 AM
šŸ’«AsšŸ’«
šŸ’«AsšŸ’« - avatar
+ 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);
3rd Oct 2020, 6:26 AM
Odyel
Odyel - avatar