• Post Reply Bookmark Topic Watch Topic
  • New Topic

why compiler treats for loop as incorrect  RSS feed

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below code works fine


but if remove initialisation for grade I am getting an error.





I understand that char cannot be empty but why its showing errors in for loop


 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
somashaker goud wrote:
I understand that char cannot be empty but why its showing errors in for loop


Basically, once the compiler finds an error, it has to move on and find the next error. The problem with moving on and finding the next error, is that it is an error situation. The developer made a mistake, and all the compiler knows is that it is not conforming to specification. It can only guess on the mistake itself -- and hence, guess on where the mistake ends.

This is why you should always work on the first few compiler errors. Compilation errors that appear later may be false positives. And also, some compilation errors that "appear" later may not even be found.

Henry
 
Saloon Keeper
Posts: 3331
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler is complaining about an empty character literal. This means that you have two single quotes back to back without a character in between them. Your second listing shows a single space between them so I'm assuming that you removed that prior to compiling.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!