Skip to main content

All Questions

Tagged with
-5 votes
1 answer
1k views

How do I manage multiple nested for-loops without using multiple variables?

If I have code that looks like this: int i; void functionA (){ for (i=0; i<10; i++){ functionB(); } } void functionB (){ for (i=0; i<20; i++){ doSomething(); } } ...
Noah Smith's user avatar
1 vote
4 answers
1k views

Should I always use iterators when working with strings?

Here is the known old way to iterate over the string: for (int i = 0; i < str.length(); i++) { char c = str[i]; } However recently I have also seen in multiple places the usage of ...
h23's user avatar
  • 121
2 votes
2 answers
4k views

Can nested loop have linear time complexity

I was going through the traditional quick sort algorithm. I had a look on the partition algorithm in a couple of places and the implementation difference was very subtle. Here are the 2 approaches: ...
arnie7's user avatar
  • 33
13 votes
7 answers
12k views

Best practice to "continue" from inside a nested loop?

Here is a simplified sample. Basically, it does checks on a string from a string list. If the check passes, it will remove that string (filterStringOut(i);), and it is no longer ...
Anon's user avatar
  • 3,613
1 vote
2 answers
2k views

How to return boolean result from comparison loops to maintain better readability?

Let's consider I have an std::string instance filled with textual data and an std::set<std::string> instance with keywords. I would like to know whether the text stored inside the std::string ...
Akira's user avatar
  • 247
8 votes
5 answers
55k views

How to structure a loop that repeats until success and handles failures

I am a self-taught programmer. I started programming about 1.5 years ago. Now I have started to have programming classes in school. We have had programming classes for 1/2 year and will have another 1/...
wefwefa3's user avatar
  • 1,007
-1 votes
4 answers
471 views

Are for loops supposed to be read inward or outward? [closed]

for (i = 0; i < 3; i++) { for (j = 0; j < 4; j++) { cout << arr2d[i][j] << "\t"; } cout << endl; ..... Like that for example. Do you read the ...
ikabod197's user avatar
0 votes
3 answers
25k views

2 Dimensional Arrays in C++

I started learning arrays in C++ and came over a little side note in the book talking about 2D arrays in breif. I tested it out and i was amazed that it could give the programmer the ability to store ...
Mohamed Ahmed Nabil's user avatar