Loops with continue and break statements¶
-
Write code to search through a list
groceries
for the string “eggs”. When you find “eggs” in the list, printFound it!
and discontinue searching by usingbreak
. If “eggs” is not found in the list, nothing is printed.Use afor
loop, containing anif
statement, containing thebreak
statement.
-
Write code to search through a list
groceries
for the string “eggs”. When you find “eggs” in the list, printFound it at index <n>
(where <n> is the index of where “eggs” was found) and discontinue searching by usingbreak
.Use an index-basedfor
loop. If you need more hints, see the previous question’s hint.