                                   5. 

                          5.1.    

       .    :

   ; //  

      ,   ++  
,    . ,    while,
    ,     
  (  ).     ++
 while   .      ( 
 ),     :

   while ( *string++ = inBuf++ )
      ; //  

          
 ,   .
           ,
   :

        ,  ,    
   .
        .   
     :

   while ( *string++ = *inBuf++ )
   {} //  

    ,   ,   .
        , 
  ( temp   ),    . (, 
        8.)

                          5.2.  

    70-       , 
        , 
 . ( , ,    
      .)     
       ,
 .   , , FORTRAN.

      ,    
,    .      
   ,    :

          
      .     
          ;
      ,       ,  
           . , 
            :  
              
      .       
     .    inBuf  next     ,
             
         .


                                   5.3.  if

       .
     if-else     ,
  else ,   if.
   (      else).
            if 
 :

        .   
          
,       .     
   . (-    7.3.)
     -    
pair,    3.14.

205

                               5.4.  switch

       case     , 
  :

   //   
   case ival: //  
   case 3.14: //  

       switch     ,  
   .
      if-else ,    ,  
 ,     case   default.   
.
    - ,        break, 
      .
                 
  .    ,   case     .
         , 
        :

   switch ( ch )
   {
      //  
      case 'a': case 'e':
      case 'i': case 'o': case 'u':
        ++vowe1Cnt;
        break;
   }

     break        
switch,   - .  :    
     case,      
 break.
      switch   ,   
:

   switch( int ival = get_response() )

ival  ,   get_response(),   
    case.  ival    switch,
   .
          switch  .
      ,       
 switch,       ,  
    case.
          ,  
 file_name   .  
,       ,    
  .     :

   case ok:
      {
         // 
         string file_name = get_file_name();
         // ...
         break;
      }


                          5.5.   for

     ,      for,
  .
       ++  ,   
 for,      ,   .
,    for   

                               5.6.  while

220

                              5.8.  do while

        , do while     
  .    :

   // :  
   //    
   do {
      // ...
      mumble( foo );
  } while ( int foo = get_foo() ) // 

      do while     
  .

                                   5.8.  break

    break   if,       switch,  
 :

                                    5.9.  continue

    continue        
 ,     .    
break,    ,  continue 
   .

                                    5.10.  goto

     
   ,       .

                              5.11.   

      3  4        ++. 
    ,   ,  
 . (  6    ,  
 .)
       ,    
       (    
   ).
      size()   ,  
.        ;  

227

,      insert()  remove() 
    .
    insert()      :    
    ,     .
      ,     
   .     
  find()      :
         :      .
          , 
    :
     (list)    (list_item)    
. (  ,     
.      ilist  ilist_item.)
    _value  ,  _next      0.
    ilist_item       
   ilist_item.    ,  
 ilist_item      .
        ,       .
      ,     
   .     ? 
  ,    abort(),  
  cstdlib:

   abort();

    ,    assert().     
,     :
       :
          :  
       ,  
    .
         ,   , 
   :    
  ,      .
        ,      
        ,    
.       
       .    
    ,      .
          
.   ,   
,      (, ,   
,     ),      
  .      -
,    . (  14.5 , 
        .) 

243
 ,   insert_end():

   ilist::ilist( const ilist &rhs )
   {
      ilist_item *pt = rhs._at_front;
      while ( pt ) {
         insert_end( pt->value() );
         pt = pt->next();
      }
   }

        remove_all(),    
insert_end()     .   
   ,      insert_all():

         :

          ,
      _at_front:

    ilist_item::next(),     -:

      ,   :   
   .       
  :

   (  2.8     .   6  12  
         
.)
        ,   .  
   ,    ,  
 .      _at_front,
         .
next_iter()     0,    . 
     :
   next_iter()   _current      
,    .      0  
_current  0.      :

    ,    _current, ,   . 
    remove()  remove_front():  
  _current.      , 
  ,         0, 
         .
    ,      ,    _current?
 _current  .       
  init_iter(),       . 
       _current  , 
  0.


                            5.11.1.  

     class  typename   ,  
  .     typename    ++
       .

   list_item<doub1e> *ptr = new list_item<doub1e>( 3.14 );

   (        ++. 
 6      , 
  ++. ,     ,
   ,     , 
;      2  3.)

           . 
     list, ,  ,  
   .        
 . ,     ,  
    .
     ++   
  std.        :

   namespace Primer_Third_Edition
   {
      template <typename elemType>
      class list_item{ ... };

      template <typename elemType>
      class list{ ... };
      // ...
   }

           
:

   //   
   #include "list.h"
 
   //      
   using namespace Primer_Third_Edition;

   //      list
   list< int > ilist;
   // ...


                                 5.16

        ilist_item,     
  .    ,    
  ,   _next, , ,  
   .     
,    ilist_item:
      remove_all()  remove_front()  ,  
   .

   ilist_item::~ilist_item()
   {
      delete _next;
   }

