Skipping and stopping during batch acceptance

A packaging script scans proposed batch masses in kg. A negative entry is an invalid reading and is skipped. An entry above 8 kg stops the scan before that batch is accepted.


MATLAB
acceptedMass = 0;          % kg
for mass = [4 -1 6 9 3]
    if mass < 0
        continue
    end
    if mass > 8
        break
    end
    acceptedMass = acceptedMass + mass;
end


What is the final value of acceptedMass?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Conditional Statements and Loops Questions: