Last active
July 26, 2016 02:59
-
-
Save afnanenayet/eb5ec168b389c501eee8c218f6aa4832 to your computer and use it in GitHub Desktop.
Different ways to construct the same loop in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiles on LLVM version 7.3.0 (clang-703.0.31) with -std=c++14 flag