mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +01:00
The snippet: boolean wrapNeeded = false; if (wrap && nextIndex == -1) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } Can be moved inside the `if (nextIndex == -1)` that follows, this way: if (nextIndex == -1) { boolean wrapNeeded = false; if (wrap) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } [...CUT...] if (wrapNeeded) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } but since `wrapNeeded` is used only at the very end of the `if` statement we can move it forward: if (nextIndex == -1) { [...CUT...] boolean wrapNeeded = false; if (wrap) { // if wrapping, a second chance is ok, start from the end wrapNeeded = true; } if (wrapNeeded) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } } and finally simplify it by removing `wrapNeeded` altogether: if (nextIndex == -1) { [...CUT...] if (wrap) { nextIndex = backwards ? text.lastIndexOf(search) : text.indexOf(search, 0); } }