Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java not a statement error at i < j

Tags:

java

When trying to compile a class, I am getting the following error;

ExcelReportServlet.java:341: error: not a statement
/* 302 */     for (Iterator localIterator = keyset.iterator();localIterator.hasNext(); i < j)

                                                                                         ^
1 error

The particular code is as follows;

int j;
int i;
for (Iterator localIterator = keyset.iterator(); localIterator.hasNext(); i < j)

What am I doing wrong? Please help...

like image 580
narenfern Avatar asked Jun 08 '26 23:06

narenfern


2 Answers

If (i<j) is a condition that controls the termination of the for loop, it should be in the second part of the for statement.

For example (not sure if that's the required logic) :

for (Iterator localIterator = keyset.iterator(); localIterator.hasNext() && i < j;)
like image 197
Eran Avatar answered Jun 10 '26 11:06

Eran


i < j is not a StatementExpression. And according to JLS(§14.14), the rightmost part of for loop is defined as ForUpdate which is in return a StatementExpressionList (a list of StatementExpression).

like image 34
Nir Alfasi Avatar answered Jun 10 '26 11:06

Nir Alfasi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!