Here is this code step by step:
SET list TO [3, 6, 9, 13, 17, 21]
You have a list of things you are going to do something with. The numbers you are going to do something with are 3,6,9,13,17 and 21 in that order.
SET found TO False
Set up a variable to signal (flag) to you when you have found something that you are looking for.
RECEIVE item FROM (INTEGER) KEYBOARD
Accept some input from the user. It must be an integer (whole number) and we are going to call it "
item
"
I'm going to pause here as I think this is the bit that you are struggling with.
Each number in that list we set up at the beginning has a "position" in the list.
3 is 1st, 6 is 2nd, 9 is 3rd etc.
We refer to that position as it's "index". In many programming languages that index starts at
0
. I.e.
3 is 1st, has index 0
6 is 2nd, has index 1
9 is 3rd, has index 2
...
21 is last, has index 5
The list also has a concept of "length" - or the number of entries in the list. In this case we have 6 entries in the list. But remember, the index of each item started at
0
! If we tried to look at the list's item at position index
6
we would get an error ... remember the index of the last number (21) is
5. So this line:
FOR index FROM 0 TO LENGTH (list) - 1 DO
means "step through the list items one-by-one starting at the beginning (
0) right through to the end (length
- 1)
if item = list[index] THEN
This line is checking to see if the
item
that the user entered via the keyboard is the same as (=) the number that is at position
index
in the list. So the first time through it will check
item = list[0]
then the next loop will check
item = list[1]
If the numbers do match then perform the actions that follow up to the
END IF
I.e.
SET found TO True
SEND 'Found' TO DISPLAY
The first line is setting that "flag" or "signal" to True, which means "yes, we have found a match". You then let the user know it's been found by displaying the word 'Found'.
Does that help?
As OriginalGriff has pointed out this is
not the way to learn. I'm hoping that this detailed explanation is going to be sufficient to let you carry on on your own now. I'm afraid you will get short shrift if you keep posting questions like this. We are not a tutorial site.