How can I improve this while loop code snippet?
Sean Francis N. Ballais
Posted on April 8, 2018
So, I have this code snippet.
while (!Character.isWhitespace(this.source.charAt(this.currentCharIndex))) {
char c = this.source.charAt(this.currentCharIndex);
// ...
}
What it does is just basically loops through a string until it hits a white space character.
However, I find the code a bit messy. How can I improve it?
I can try this code snippet instead.
char c = this.source.charAt(this.currentCharIndex);
while (!Character.isWhitespace(c)) {
c = this.source.charAt(this.currentCharIndex);
}
It looks cleaner but this.source.charAt(this.currentCharIndex)
seems redundant (the same as the previous snippet) so I need your opinion on how you would tackle this problem.
Thanks! :D
đź’– đź’Ş đź™… đźš©
Sean Francis N. Ballais
Posted on April 8, 2018
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
undefined Understanding NLP: Challenges and Solutions in Human-Machine Communication
November 29, 2024