private void onOffLoop(float onTime, float offTime, int n, Action stopAction) throws RuntimeIOException { running = true; if (n > 0) { for (int i = 0; i < n && running; i++) { onOff(onTime, offTime); } } else if (n == INFINITE_ITERATIONS) { while (running) { onOff(onTime, offTime); } } if (stopAction != null) { stopAction.action(); } }