Answer the question
In order to leave comments, you need to log in
Endless loop or unnecessary variable behind the loop?
From time to time I meet with tasks where it is necessary to twist a variable inside the loop and end the loop when it reaches a certain value. There are two options for implementing this algorithm:
1. An infinite loop with exit inside
do {
int myVar = getVar();
// логика работы с myVar
if (myVar <= 0)
break;
} while (true)
int myVar = getVar();
while(myVar > 0) {
// логика работы с myVar
myVar = getVar();
}
Answer the question
In order to leave comments, you need to log in
1. Endless loop with exit inside
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question