Hi!
As some of you may know, I'm currently learning C++ and would like to know something; I know that many of the loops in C/C++ can be represented using a regular while loop. In the following examples, please correct me if I'm wrong:
Representing a while-statement using a do-statement
Representing a for-statement using a do-statementCode:do { if (/* condition */) { // ... } else break; } while (true);
Representing a while-statement using a for-statementCode:int i = 0; do { if (i < MAX) { // ... i++; } else break; } while (true);
Representing a do-statement using a for-statementCode:for (; /* condition */;) { // ... }
These are my guesses at the moment. Please feel free to correct me if I happened to make a mistake in any of those or if you see that any of them are inefficient (say, if I included something that was not necessary and there is a better way to represent the same thing, etc.)Code:// the statements go here... for (; /* condition */;) { // same statements as above... }
Thanks!




Reply With Quote