java - Error message 'else' without 'if' when for looping -
basically, trying nest loop , output around lines this:
* ** *** // (and on)
unfortunately keep getting error message when coding, here code (i documented place have error):
for (int = 0; i< 9; = + 2) { system.out.print(i + " "); (int j = 1; j<=3; j = j + 1) { if (i==8); break; } else //this else statement underlined { system.out.print("*" + " "); } }
i using java netbeans ide 8.0 if interested.
the problem in semicolon in end of if :
if (i==8); //-------^ break;
so when make semi-colon in end of if mean statement end start new statement break;
to understand more, did have do, mean :
if (i==8);//end of statement break;start new statement
the above equivalent of :
if(i==8){ //do nothing } break;
to solve problem need use instead :
if(i==8){ break; }
Comments
Post a Comment