Hey guys,
why does the following get me an infinite loop?
size_t should be able to take the value of 0, so what seems to be the problem here?Code:for (size_t i = myString.length() - 2; i >= 0; --i) { cout << "test" << endl; }
This is a discussion on infinite loop using string and size_t within the C++ Programming forums, part of the General Programming Boards category; Hey guys, why does the following get me an infinite loop? Code: for (size_t i = myString.length() - 2; i ...
Hey guys,
why does the following get me an infinite loop?
size_t should be able to take the value of 0, so what seems to be the problem here?Code:for (size_t i = myString.length() - 2; i >= 0; --i) { cout << "test" << endl; }
Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
Operating system: Ubuntu GNOME 13.04 (Raring Ringtail) (64-Bit) / Linux 3.8.0-16.26 / GNOME 3.6.2
Compiler: gcc 4.7.3
size_t is unsigned, so >= 0 is always TRUE.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
Damn, how stupid was THAT?
Thanks.
Hardware: Intel® Core™ i7-3630QM CPU @ 2.40GHz × 8
Operating system: Ubuntu GNOME 13.04 (Raring Ringtail) (64-Bit) / Linux 3.8.0-16.26 / GNOME 3.6.2
Compiler: gcc 4.7.3