DEV Community

Discussion on: How can I improve this while loop code snippet?

Collapse
 
fnh profile image
Fabian Holzer • Edited

Well, you give very little context about your intentions.

If it is safe to assume that currentCharIndex is within the correct bounds, you might get rid of the assignment outside of the loop by using do { } while.

Or, you get rid of the imperative style by using Streams (you get an IntStream from a String using the chars() method in Java 8).

Collapse
 
seanballais profile image
Sean Francis N. Ballais

Interesting. I'm actually creating a tokenizer for a programming language we came up as part of our course curriculum.