Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Invalid AssignmentOperator when trying to use / in a for loop in Java

I’m trying to use / in a for loop as the action to complete after each iteration, but I’m getting an "invalid AssignmentOperator" error. I’m using Java SE 17.

Here’s the relevant code:

for (i = num/2; i >= 0; i / 2) {
            
}

All variables are integers and already defined. The error continues even if I make the first statement one that doesn’t use /, so it’s not an issue with i being assigned to num/2 (other than any problems that may be happening with the / symbol itself).
Why am I getting this error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

i / 2 is not an assignment operation.

Try i /= 2 or i = i/2

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading