| | |
Bubble Sort
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
In niek_e's example, the init-expression, cond-expression, and loop-expression are all optional as long as you include the separating semicolons. That's why an infinite "forEVER" loop looks like this:
As long as the loop does what you want, the syntax is very flexible. In Ed's experience, the usual culprits are a very long initialization that makes the loop line too long and a more complicated update:
Cool, huh?
C++ Syntax (Toggle Plain Text)
for (;;) { ... }
C++ Syntax (Toggle Plain Text)
// So long it makes more sense outside the loop std::vector<std::pair<std::string, double> >::size_type index = 0; for (; index != v.size(); ++index) { ... } // As a part of the loop (too long) for (std::vector<std::pair<std::string, double> >::size_type index = 0; index != v.size(); ++index) { ... }
C++ Syntax (Toggle Plain Text)
// n isn't incremented with every loop for (n = 0; n < 10 && std::getline(std::cin, input); ) { if (input[0] == '*') ++n; }
If at first you don't succeed, keep on sucking until you do succeed.
Reiterating the point, niek_e made, its possible. All of them are not necessary, in fact none are.
Also, I did not want to use sort variable outside the loop, so I used it inside as, if there are more bubble sorts and I use the sort variable again and don't initialize it, well, that would give me some headache. Won't it?
Also, I did not want to use sort variable outside the loop, so I used it inside as, if there are more bubble sorts and I use the sort variable again and don't initialize it, well, that would give me some headache. Won't it?
[Catchy Signature Here]
![]() |
Similar Threads
- bubble sort function w/ array (C++)
- How do i change this JAVA Insertion sort object to Bubble Sort object (Java)
- Bubble Sort of a file of records in Pascal pls (Pascal and Delphi)
- simplified bubble sort c++ (C++)
- Bubble sort & File output jibrish errors??? (C)
Other Threads in the C++ Forum
- Previous Thread: Read File>>>>
- Next Thread: Data base connection with c++
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





