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

Python backwards for loop converted into java, not working

I am so triggered by this. I am rewiriting a piece of python code into java. And my program has not been working. I have just found out why. It is the backwards for loop!

Python

for i in range(len(array) - 1, 2, -2): 

MY written in java

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

for (int i = diff.size() - 1; i < 2; i = i - 2) {}

I’ve been pulling my hair out. Does anyone know what is wrong??!!!

>Solution :

The Java version terminates when i >= 2, while the Python version terminates i <= 2. To fix, the loop condition should be i > 2 for the Java version.

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