Skip to content

Instantly share code, notes, and snippets.

@mtao
Created October 13, 2017 13:32
Show Gist options
  • Save mtao/aa86e92e0e0813e7e9d8162929107afa to your computer and use it in GitHub Desktop.
Save mtao/aa86e92e0e0813e7e9d8162929107afa to your computer and use it in GitHub Desktop.
simple case to remind myself how for loops work
#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