• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

c++ for loop question

hollowman

Diamond Member
in c++, what does for ( ; ; ) do?

I thought for loop at least require a conditional statement?

example of the code would be...


//code starts here

void Huffman::buildDecodingTree(ifstream & codeIn)
{
char ch; // a character
string code; // its code
for ( ; ; )
{
codeIn >> ch >> code;

if ( codeIn.eof() ) return;
insert(ch, code);
}
}

so what exactly is for ( ; ; ) doing in this snippet of code?
thank you for your help.
 
Originally posted by: xtknight
As far as I know, it's an infinite loop.

hmm.. so then i guess when it is used with inputFileStream, it will halt when there is no more information to read in?

because i have ran the program above and it does halt after reading in the file completely.
 
Yup...

if ( codeIn.eof() ) return;

This breaks it out of the infinite loop (actually out of the function).
 
Back
Top