automatic fail safe for infinite loops?

good evening! i am very new to C++ and am exploring the for loop.
my assignment asked for a for loop that increments a variable but i accidentally made an infinite loop. instead of adding the numbers between 1 and 10 it's adding the numbers after 10 with no limit.
my computer took a minute to execute the loop and ended at a value of 1 billion something. i understand my coding mistake but im baffled at the sudden end. is there a built-in fail safe for C++, the <iostream> library, or my compiler (code::blocks with gnu gcc compiler)? if it falls within the compiler that's a fine answer and i can ask the proper questions in the proper places.
thanks for your time! sorry if this has been asked before but it's been hard to google the proper answer when im not sure how to phrase the question.
The conditional statements in loops are supposed to be that failsafe. Main paradigm in C++ is "Trust the programmer". With many uses for infinite loops (terminating on demand) there is no way to tell if infinite loop intended or not. You need to be careful.

C is a razor-sharp tool, with which one can create 
an elegant and efficient program or a bloody mess.
                  —Brian Kernighan, Rob Pike. “The Practice of Programming”.
Last edited on
my infinite loop was unintended. does c++ have a 2nd fail safe, like int var has a range of (-10000 < x < 10000)? is there a limit on the variable so it doesn't crash your computer in case of my mistake?
is there a limit on the variable so it doesn't crash your computer in case of my mistake?

what you experience was the overflow of a numeric integral type:
#include <iostream>
#include <limits>

int main () {
  int i = std::numeric_limits<int>::max();
  std::cout << "Max signed = " << i << std::endl;
  std::cout << "Overflow = " << i << std::endl << std::endl;

  unsigned int j = std::numeric_limits<unsigned int>::max();
  std::cout << "Max unsigned = " << j << std::endl;
  std::cout << "Overflow = " << j << std::endl;

  return 0;
Max signed = 2147483647
Overflow = -2147483648

Max unsigned = 4294967295
Overflow = 0
thanks so much for your time!
Topic archived. No new replies allowed.