Loops with continue and break statements¶
-
Write code to search through a list
groceriesfor 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 aforloop, containing anifstatement, containing thebreakstatement.
-
Write code to search through a list
groceriesfor 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-basedforloop. If you need more hints, see the previous question’s hint.