Created
October 13, 2017 13:32
-
-
Save mtao/aa86e92e0e0813e7e9d8162929107afa to your computer and use it in GitHub Desktop.
simple case to remind myself how for loops work
This file contains hidden or 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> | |
| int main() { | |
| constexpr static int N = 20; | |
| for(int i = 0; i < N; ++i) { | |
| std::cout << i << ", "; | |
| } | |
| std::cout << std::endl; | |
| for(int i = 0; i < N; i++) { | |
| std::cout << i << ", "; | |
| } | |
| std::cout << std::endl; | |
| auto start = []()->int{std::cout <<"start(i=0)" << std::endl; return 0;}; | |
| auto check = [](int i) -> bool { std::cout << "check(" << i << "<" << N << ")" << std::endl; return i < N; }; | |
| auto increment = [](int i){std::cout << "Increment(" << i<<"++)"<<std::endl; return i+1;}; | |
| for(int i = start(); check(i); i=increment(i)) { | |
| std::cout << "content(f(" << i << "))" << std::endl; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment