Skip to content

Instantly share code, notes, and snippets.

@afnanenayet
Last active July 26, 2016 02:59
Show Gist options
  • Save afnanenayet/eb5ec168b389c501eee8c218f6aa4832 to your computer and use it in GitHub Desktop.
Save afnanenayet/eb5ec168b389c501eee8c218f6aa4832 to your computer and use it in GitHub Desktop.
Different ways to construct the same loop in C++
#include <iostream>
using namespace std;
#ifdef __cplusplus
extern "C" {
#endif
void loop();
#ifdef __cplusplus
}
#endif
void loop(){
int i = 5;
while (i --\
\
\
\
\
\
> 0) {printf("%d\n", \
\
\
\
\
\
\
i\
)\
\
\
;\
\
}\
// \ // \ //
// -------- \
ayyyyyyy lmao
}
int main() {
for (int i = 4; i >= 0; --i) {
cout << i << "\n";
}
int i = 5;
while (i --> 0) {
cout << i << "\n";
}
i = 5;
while (i > 0) {
cout << --i << "\n";
}
for (int i : {4, 3, 2, 1, 0}) {
cout << i << "\n";
}
loop();
return 0;
}
@afnanenayet
Copy link
Author

Compiles on LLVM version 7.3.0 (clang-703.0.31) with -std=c++14 flag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment