I had and error in my code where I accidentally typed i << foo.length()
instead of i < foo.length()
in my for loop condition, forcing the loop to immediately quit. I was wondering how I could avoid such error in the future.
Asked
Active
Viewed 84 times
2
-
4Perhaps use iterators? – DYZ Apr 06 '17 at 12:47
-
3They way to avoid loop problems is to not use loops ;). A lot of what you want to do can already be found [here](http://en.cppreference.com/w/cpp/algorithm) – NathanOliver Apr 06 '17 at 12:47
-
1Use range for? Static analyzers? Code review? (From Sean Parent's [talk](https://channel9.msdn.com/Events/GoingNative/2013/Cpp-Seasoning): No raw loops) – Borgleader Apr 06 '17 at 12:47
-
Learn touch typing. It lets you look at the text you are typing while you are typing it. This allows you to ensure that what you type is actually what you want to type. I can't recall making such an error: Whenever I made an error, I meant what I wrote, it does not happen that I type something other than what I intended to type. – cmaster - reinstate monica Apr 06 '17 at 12:58
-
1@DYZ thank you iterators sound like the best solution. – Anže Apr 06 '17 at 13:15
-
@Borgleader thank you for the link, very interesting lecture – Anže Apr 07 '17 at 08:46