- Joined
- Apr 22, 2005
- Sythe Gold
- 23
- Messages
- 7,825
If you're used to using Pascal-based languages such as SCAR or Delphi, you're probably familiar with the syntax of a repeat-until loop. While C/C++ has no innate support for an equivalent to a repeat-until loop, it is possible to use preprocessor macros to create one.
See here:
Macros created with the define statement are replaced with actual code when they are compiled. For example, if you were to save and view the intermediate (processed, .ii) C++ source file, the main() function would be:
It works just as you would expect it to. This is just a source, not a tutorial, so I won't go any more in depth on it. If you already know general programming concepts this shouldn't be hard.
See here:
Code:
#include <iostream>
using namespace std;
#define REPEAT do{
#define UNTIL(expr) }while(!(expr))
int main(int argc, char *argv[])
{
int i = 0;
REPEAT
cout << "i: " << i << endl;
i++;
UNTIL(i==10);
return 0;
}
Macros created with the define statement are replaced with actual code when they are compiled. For example, if you were to save and view the intermediate (processed, .ii) C++ source file, the main() function would be:
Code:
int main(int argc, char *argv[])
{
int i = 0;
do{
cout << "i: " << i << endl;
i++;
}while(!(i==10));
return 0;
}














