Q:

Explain each of the following examples, and correct any problems you detect

0

Explain each of the following examples, and correct any problems you detect.

(a) while (string::iterator iter != s.end()) { /* . . . */ }

(b) while (bool status = find(word)) { /* . . . */ } if (!status) { /* . . . */ }

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

(a) The loop variable `iter` did not initialized before used. It should be initialized first.

    string::iterator iter = s.begin();
    while (iter != s.end()) { /* ... */ }

(b) The loop variable `status` is used outside the scope of the `while` statement, thus it should be defined outside that scope.

    bool status;
    while (status = find(word)) { /* ... */ }
    if (!status) { /* ... */ }

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now