Checking the status inside the loop

If "flag" is true, I need to perform step no. 1 otherwise skip it. Is there a way out to skip this unnecessary re-check inside the loop. (Since the flag value does not change during the execution of the loop)

private void method(boolean flag) {
        while (man > woman) {
            if (flag) {
                // Step no. 1
                System.out.println(flag);
            }
        }
    }
+3
source share
4 answers

I'm not sure it is productive to worry about optimizing at this level. As a rule, it is more important to make the program work and move on to the next problem.

, , loop unswitching, . , , . ( , , .)

, , , , .

, , , , ...

, . , . , , "--", ---... , . , ...

+10

do. do , , if (do). true, . ?

0

, , , do == true (, , , [ ]).

0
while (man > woman) {

Beware of endless loops here :-)

0
source

Source: https://habr.com/ru/post/1722930/


All Articles