← AP CSP Course← AP CSP 课程 ← Back to Study Guide← 返回学习指南

Filter a list with FOR EACH用 FOR EACH 筛选列表

Run one AP CSP pseudocode statement or condition check at a time. Watch scores, passing, threshold, and score change.每次执行一条 AP CSP 伪代码语句或检查一次条件,观察 scores、passing、threshold、score 的变化。

Code代码

  1. scores ← [55, 72, 80, 90, 64]
  2. passing ← []
  3. threshold ← 80
  4. FOR EACH score IN scores {
  5. IF (score ≥ threshold) {
  6. APPEND(passing, score)
  7. }
  8. }
  9. DISPLAY(passing)

State状态

Variable变量Value值
scores[55, 72, 80, 90, 64]
passing—
threshold—
score—
Condition条件—
Output输出—

Use ← and → to step. The note explains each comparison and change.使用 ← 和 → 逐步运行。每次比较和变化见下方说明。