![for each (item) of {Abraham, Lincoln} [say (item) for (1) secs] for each (item) of {Abraham, Lincoln} [say (item) for (1) secs]](/bjc-r/img/3-lists/check1abec1.png)
On this page, you will complete your quiz app by using a new block that loops through a list:
If it's not already open, open your project U2L2-Quiz.
item of
inside a for
loop and use the index from the for
loop as the first input to item of
, like this:Using the result from item
as the input to address from contact
is called composition of functions.
for each
to traverse the list.
for each
into the scripting area.Traversing a list means looking at each item of the list. For each
is iterative. That is, it's repetitive, like for
, which can also traverse a list. But unlike for
, for each
traverses the list without using index numbers.
for each
to traverse your list, asking each quiz question, checking each answer, and letting the user know if they are right or wrong on each item.
Which of the scripts below will produce the following sprite behavior?
(When you run the script, though, it actually says Abraham Lincoln only once.)
Choose all that apply.
goto()isn't built in to the AP's language so it is written in lower case like other programmer-defined procedures.
FOR EACH point IN myDrawing { goto(point) }
goto
procedure had to have been defined (as we do with the college board stuff just above and to the right?? --MF, 2/20/25
for each point in myDrawing:
goto(point)
These questions are similar to those you will see on the AP CSP exam.
inputList ← [3, -1, 2, 10, -5] FOR EACH item IN inputList { IF(item > 0 AND item * item > 4) { DISPLAY(item) } }
IFinstruction test? What does the
DISPLAYinstruction in this code display?
DISPLAYinstruction in this code display?
PROCEDURE Mystery(numberList, targetNumber) { counter ← 0 FOR EACH number IN numberList { IF(number > targetNumber) { counter ← counter + 1 } } RETURN(counter) } myMathGrades ← [100, 80, 90, 80, 60, 100, 50, 100] Mystery(myMathGrades, 60)
question answer
ADT could take a list of keywords in the second slot and accept any answer that includes any of the keywords (so in this case, the list would be {local, script} and would accept "a local one"). Use