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”.
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?