Question: 2 2 . Reflect on Exercise 4 What we had you do with first _ vowel may seem weird. At first we had you return

22. Reflect on Exercise 4
What we had you do with first_vowel may seem weird. At first we had you return the length of the string if no vowel was found. Then we had you change it to -1 at the very end. Why do it this way? Why not make a failed find return -1 in the very beginning, especially since this is how the function find_str in introcs works?
You could have done it this way. You could have written your code as follows:
result =-1 # Nothing found yet
if something
do something
...
return result
skipping over each if statement if the vowel is not there.
But you would have to change your if statements a lot to account for this. And depending on your comfort with boolean expressions, you might find it harder to do it this way. What do you think?
Do you think our approach was easier than starting with -1? Why or why not?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!