Home > Back-end >  For in the c language, while, do... The difference between the while
For in the c language, while, do... The difference between the while

Time:10-13

Would you help me to explain the for loop in c language statements, while, do... While the difference between, and actual application

CodePudding user response:

Difference between how this can explain, don't like the book says the
?
Usage scenario, while for an infinite loop
Whlie (true)
{
//infinite loop
}

Suitable for words count

//do a repeat of 100
for (int i=0; I & lt; 100; I++)
{

}

Other do not have what distinction, various circulation can achieve the same goal, it's just whether convenient, you can need not consider the performance gap between them


CodePudding user response:

The do... Run at least once a while for the ~

CodePudding user response:

For can manage all requirements

CodePudding user response:

Seldom used the do... Wile
For fine

CodePudding user response:

Generally speaking, the loop body same words
While efficiency is higher than the for, but the speed is more do not have what meaning, the key or the loop body

For more flexible, the do... While the flow chart is more easy to understand

CodePudding user response:

Essentially no difference, different wording,