AP Computer Science Principles by Seth Reichelson

AP Computer Science Principles by Seth Reichelson

Author:Seth Reichelson [Seth Reichelson]
Language: eng
Format: epub
Publisher: Barrons Educational Series
Published: 2020-04-28T00:00:00+00:00


Example Nineteen

Searching for a Word in a Text-Based Coding List

Line 1: PROCEDURE findNumber (list, word)

Line 2: {

Line 3:index ← 1

Line 4:FOR EACH item IN list

Line 5:{

Line 6:if (item = word)

Line 7:{

Line 8:RETURN index

Line 9:}

Line 10:index ← index + 1

Line 11: }

Line 12: RETURN (“Word not in list”)

Line 13: }

Line 3: Initialize the variable index to equal one, since that is where to begin the search for “word.”

Line 4: This For Each loop will loop for every item in the array. Each iteration then looks at the next object in the array, calling it item.

Line 6 to Line 9: If the current item is the same as the word being searched for, it will return that given index.

Line 10: If the word did not match with the item, continue with the program and increment the index.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.