Programming Fundamentals Quiz: Variables and Loops

Programming Fundamentals: Variables and Loops: ten questions on state, loops, and scope. Includes calculations; answers explained.

Free, with no sign-up.

For High school students and adults reviewing the topic.

About 10 minutes. 10 questions.

How does it work?

  1. Choose one answer or enter a number in the stated unit, then check it.
  2. Read the explanation before continuing.
  3. Round only the final answer to the precision requested.

What will you get?

See your score and review the reasoning behind each answer.

Question 1A counter starts at 4 and gains 3 on each of five iterations. Find its final value as a whole number with no unit.

Answers within 0.5 of the expected value are accepted.

Question 2An accumulator starts at 2 and adds each integer from 3 through 6 inclusive. Find the final value as a whole number with no unit.

Answers within 0.5 of the expected value are accepted.

Question 3A variable starts at 5. A loop doubles it on each of four iterations. Find the final value as a whole number with no unit.

Answers within 0.5 of the expected value are accepted.

Question 4A program executes score = score + bonus as an assignment. What happens?
Question 5A sum is reset inside the body just before adding each new reading. What explains a final result that retains only the latest reading?
Question 6A loop visits a zero-based list and permits an index equal to its length. What boundary problem follows?
Question 7A condition needs checking once to decide whether to apply a discount. Which construct expresses that job?
Question 8In a while loop intended to finish at zero, a positive stock count stays unchanged. Which change addresses the cause?
Question 9Two functions each declare a local variable named total. What does local scope provide?
Question 10A program produces a plausible total on a large input, but its update rule is uncertain. What test gives direct evidence?

Answer every question to see and share your score.

Read the topic guide