Subj : Re: while(in) To : borland.public.cpp.borlandcpp From : Les Hurley Date : Mon Mar 22 2004 10:03 pm ps Wayne's method works just fine. Thanks. Les Hurley wrote: > Well here is the helpfile description of while: > Syntax > while [( condition )] [{statement_list}] > > condition Either TRUE or FALSE. When FALSE, statement_list stops > executing. > statement_list The list of statements to execute. > > Description > If no condition is specified, the while clause is equivalent to > while(TRUE). > Because the test takes place before any statements execute, if > condition > evaluates to FALSE on the first pass, the loop does not execute. > > This sounds to me like the condition is tested before the statement > block is > entered and no statements executed if the condition is false. > > "Wayne A. King" wrote: > > > On Sun, 21 Mar 2004 23:05:26 -0500, Les Hurley wrote: > > > > > while(in){in>>n; > > > cout< > > > End of file is set when you try to read *past* the last data in the file. > > Thus the eof flag gets set the first time your in >> n extraction fails. > > But you're displaying the variable n even when the extraction fails, > > and it still contains the value from the last successful extraction. > > See if this works better: > > > > while(in >> n){cout< > > > -- > > Wayne A. King > > (waking@idirect.com, Wayne_A_King@compuserve.com) .