Looping with cppitertools

range

Looping to a stop

#include <iostream>
#include <range.hpp> //from https://github.com/ryanhaining/cppitertools
int main(int argc, char* argv[]){
    for(auto pos : iter::range(10)){
        std::cout << pos << "\n";
    }
    return 0;
}
Compile Command:
g++-5 -std=c++14 -I../cppSetupTools/external/local/cppitertools/v0.1/cppitertools/ main.cpp -o exampleCpp
Execution Call:
./exampleCpp
Output:
0
1
2
3
4
5
6
7
8
9

Looping from a start to a stop

#include <iostream>
#include <range.hpp> //from https://github.com/ryanhaining/cppitertools

int main(int argc, char* argv[]){
    for(auto pos : iter::range(3,10)){
        std::cout << pos << "\n";
    }
    return 0;
}
Compile Command:
g++-5 -std=c++14 -I../cppSetupTools/external/local/cppitertools/v0.1/cppitertools/ main.cpp -o exampleCpp
Execution Call:
./exampleCpp
Output:
3
4
5
6
7
8
9

Looping from a start to a stop with step

#include <iostream>
#include <range.hpp> //from https://github.com/ryanhaining/cppitertools

int main(int argc, char* argv[]){
    for(auto pos : iter::range(0,10, 2)){
        std::cout << pos << "\n";
    }
    return 0;
}
Compile Command:
g++-5 -std=c++14 -I../cppSetupTools/external/local/cppitertools/v0.1/cppitertools/ main.cpp -o exampleCpp
Execution Call:
./exampleCpp
Output:
0
2
4
6
8

Looping, going down

#include <iostream>
#include <range.hpp> //from https://github.com/ryanhaining/cppitertools

int main(int argc, char* argv[]){
    for (auto i : iter::range(2, -3, -1)) {
      std::cout << i << std::endl;
    }
    return 0;
}
Compile Command:
g++-5 -std=c++14 -I../cppSetupTools/external/local/cppitertools/v0.1/cppitertools/ main.cpp -o exampleCpp
Execution Call:
./exampleCpp
Output:
2
1
0
-1
-2

Looping, using fractional step

#include <iostream>
#include <range.hpp> //from https://github.com/ryanhaining/cppitertools

int main(int argc, char* argv[]){
    for(auto i : iter::range(5.0, 10.0, 0.5)) {
      std::cout << i << std::endl;
    }
    return 0;
}
Compile Command:
g++-5 -std=c++14 -I../cppSetupTools/external/local/cppitertools/v0.1/cppitertools/ main.cpp -o exampleCpp
Execution Call:
./exampleCpp
Output:
5
5.5
6
6.5
7
7.5
8
8.5
9
9.5

Looping examples that will end up producing no iterations

#include <iostream>
#include <range.hpp> //from https://github.com/ryanhaining/cppitertools

int main(int argc, char* argv[]){
  //iterating to the same stop as your start will produce nothing
  std::cout << "Start loop example 1" << std::endl;
  for(auto i : iter::range(1,1)) {
    std::cout << i << std::endl;
  }
  std::cout << "End Loop example 1" << std::endl;
  
  //iterating to the a stop less than your start but wihtout a negative step will produuce nothing
  std::cout << "Start loop example 2" << std::endl;
  for(auto i : iter::range(1,0)) {
    std::cout << i << std::endl;
  }
  std::cout << "End Loop example 2" << std::endl;
  
  //iterating to just 0 will produce nothing
  std::cout << "Start loop example 2" << std::endl;
  for(auto i : iter::range(0)) {
    std::cout << i << std::endl;
  }
  std::cout << "End Loop example 2" << std::endl;
  
  return 0;
}
Compile Command:
g++-5 -std=c++14 -I../cppSetupTools/external/local/cppitertools/v0.1/cppitertools/ main.cpp -o exampleCpp
Execution Call:
./exampleCpp
Output:
Start loop example 1
End Loop example 1
Start loop example 2
End Loop example 2
Start loop example 2
End Loop example 2