C++.


for - 3


for ( int ival = 0, *pi = &ia, &ri = val;

ival < size;

++iva1, ++pi, ++ri )

// ...

: false, . , :

#include <iostream>

 

int main()

{

for ( int ix = 0;

bool done = ix == 10;

++ix )

cout << "ix: " << ix << endl;

}

, for, . , iter [8]:[O.A.2] 

int main()

{

string word;

vector< string > text;

// ...

for ( vector< string >::iterator

iter = text.begin(),

iter_end = text.end();

iter != text.end(); ++iter )

{

if ( *iter == word )

break;

// ...

}

 

// : iter iter_end

if ( iter != iter_end )

// ...

5.8

for? , ?

(a)

for ( int *ptr = &ia, ix = 0;

ix < size && ptr != ia+size;

++ix, ++ptr )

// ...

 

(b)

for ( ; ; ) {

if ( some_condition )

break;

// ...

}

(c)

for ( int ix = 0; ix < sz; ++ix )

// ...

 

if ( ix != sz )

// ...

(d)

int ix;

for ( ix < sz; ++ix )

// ...

(e)

for ( int ix = 0; ix < sz; ++ix, ++ sz )

// ...

5.9

, for . .

5.10

:

bool is_equa1( const vector<int> &vl,

const vector<int> &v2 );

, . , . , (0,1,1,2) (0,1,1,2,3,5,8) . v1.size() v2.size().