Algorithms with Flowcharts and Pseudocode

Learn to plan algorithms before you write code. Draw flowcharts with the standard symbols, write clear pseudocode with variables, decisions and loops, and trace algorithms step by step with trace tables to predict what they do. Test algorithms with well-chosen data, fix their errors, design your own, and compare different algorithms for the same task by correctness, efficiency and clarity.

Grade 6, Grade 7Lesson 2 of 10 in Computing for Ages 11 to 14 Course

What you will learn

  1. Explain what an algorithm is, plan one with its inputs, processes and outputs, and use variables to store and change values.
    • Plan an algorithm with inputs, processes and outputs
      Recognize what makes an algorithm precise, plan it with an input–process–output chart, and name the three building blocks that algorithms are built from.
    • Store and change values with variables
      Use variables, assignment, arithmetic operators, input and output, and tell assigning a value apart from comparing values.
  2. Read, draw and correct flowcharts that use the standard symbols to show sequence, decisions and loops.
    • Use the standard flowchart symbols
      Recognize each flowchart symbol and what it means, and follow the rules that make a flowchart clear and complete.
    • Show decisions in flowcharts
      Use decision symbols with comparison operators to choose between paths, including several decisions in a row, decisions inside decisions and combined conditions.
    • Show repetition in flowcharts
      Draw and follow loops in flowcharts, using a counter for a fixed number of repeats or a condition for repeats until something happens.
  3. Write clear, indented pseudocode with input, output, assignment, IF statements, loops and sub-routines, and convert algorithms between pseudocode and flowcharts.
    • Write clear, structured pseudocode
      Follow consistent pseudocode conventions with keywords, one instruction per line and indentation, and keep every step short, clear and precise.
    • Write decisions with IF statements
      Write selection in pseudocode with IF, ELSE and ELSE IF, nest one IF inside another, and combine conditions with AND, OR and NOT.
    • Write loops with FOR, WHILE and REPEAT
      Write count-controlled and condition-controlled loops in pseudocode, choose the right loop for a task, and combine loops with IF statements.
    • Convert between flowcharts and pseudocode and use sub-routines
      Turn a flowchart into pseudocode and pseudocode into a flowchart, and use named sub-routines to reuse a group of steps.
  4. Follow algorithms step by step with trace tables, predict their output, work out their purpose, and find and fix errors using planned test data.
    • Trace an algorithm with a trace table
      Work through flowcharts and pseudocode line by line, recording every change of value in a trace table to find exactly what the algorithm does.
    • Predict, test and correct algorithms
      Predict outputs, work out what an algorithm is for, plan tests with normal, boundary and invalid data, and find and fix logic errors in flowcharts and pseudocode.
  5. Design algorithms for new problems by combining sequence, selection and iteration, and judge different algorithms for the same task by correctness, efficiency and clarity.
    • Design an algorithm for a new problem
      Turn a problem into a working algorithm by finding its inputs and outputs, choosing the right constructs, writing it as a flowchart or pseudocode, and checking it with test data.
    • Compare algorithms that solve the same problem
      Judge two or more algorithms for the same task by whether they are correct, how many steps they take, how clear they are and which inputs they handle.

Flowcharts and Pseudocode study guide

5 chapters

1

Describe algorithms precisely

Planning a program begins with a precise description of its job. Identify what data comes in, what happens to it, and what result should come out. Then follow how variables hold and change values during those steps. These ideas let you check a plan before choosing a programming language, and help you spot instructions that leave the reader guessing.

1.1 Plan an algorithm with inputs, processes and outputs

An algorithm gives precise steps for completing a task. The steps have an order, a clear start, and an end. Each instruction must have one meaning, so another person can follow it without guessing.

Make the instructions precise

“Make the drink” leaves several choices unexplained. “Pour 200 ml of milk into the cup” names an action and an amount. “Repeat a few times” is vague; “Repeat 3 times” gives an exact count. A computer follows instructions literally. It cannot supply a missing calculation because the answer seems obvious.

An algorithm must give the right result for every input it is designed to handle. A plan that works for one test score but fails for another needs fixing.

Separate the plan from the program

A program expresses an algorithm in a programming language, such as Scratch or Python. A computer can run the program. A flowchart shows the plan using shapes and arrows. Pseudocode shows it using structured text. People read these plans to check the logic before writing code.

The two planning forms can describe the same steps. Flowcharts make branches easy to see. Pseudocode takes less space when there are many instructions.

Find the inputs and outputs

An input is data received by the algorithm. It might be a typed number or a sensor reading. A process works with that data through calculations, actions, or decisions. An output is a result, such as a message or a signal to a motor.

An IPO chart puts these parts in three columns. For the average of three test scores:

InputProcessOutput
Scores 72, 85, and 90Add the scores, then divide by 3Average score

The sum is 247. Dividing by 3 gives an average of 82.3 to one decimal place. The chart separates what comes in from what must be calculated. The average belongs under output, because it is the result we want.

A sensor can be an input even when nobody types anything. For a lamp controller, a light reading comes in, a decision checks it, and an output signal controls the lamp. The word “output” covers that signal as well as a message on a screen.

Choose the control structures

Three control structures organize the steps:

  • Sequence runs steps one after another.
  • Selection chooses a path using a decision.
  • Iteration repeats a group of steps.

A ticket machine can read an age, choose a price, and repeat for another customer. That plan combines all three structures. Order matters within a sequence: calculate the price before displaying it. Displaying it first could show an old value or a value that has not been set.

Break up a larger problem

Decomposition means splitting a problem into smaller parts. A checkout needs to add item prices and work out change. Plan those parts separately, then connect them in the order needed. The total price must be ready before the change can be calculated.

Key Takeaways

  • An algorithm has precise, ordered steps with a clear start and end.
  • An IPO chart separates received data, processing, and results.
  • Sequence, selection, and iteration organize algorithm steps.
  • Flowcharts and pseudocode help people plan before coding.

1.2 Store and change values with variables

A variable stores a value under a name. The algorithm can read that value and replace it as the steps run. Names such as score, total, and count tell us what is being stored.

Read assignment from right to left

Assignment stores a value. In score ← 10, read the arrow as “score becomes 10.” The variable goes on the left. The value or calculation goes on the right.

For total ← total + 3, first read the current value of total. Add 3, then store the answer back in total. If it held 5, it now holds 8. The old 5 has been replaced.

This is an instruction, so it is fine to use the same variable on both sides. count ← count + 1 increases the stored count by 1; it is not an equation claiming that a number equals itself plus 1.

An assignment such as a ← b copies the current value of b. It changes a and leaves b unchanged. Choose names without spaces, such as highScore or high_score, so each name is easy to recognize.

For example, start with a ← 2 and b ← 6. After a ← b, both hold 6. If the next instruction sets b ← 9, a still holds 6. The assignment copied a value at one moment; it did not make the two names share every future change.

Keep assignment and comparison apart
Instruction or conditionMeaning
score ← 10Store 10 in score
score == 10Ask whether score equals 10
score != 10Ask whether score differs from 10

A comparison gives true or false. It does not change the stored score.

Calculate with stored values

The arithmetic operators are + for addition, - for subtraction, * for multiplication, and / for division. Two more operators work with whole-number division:

  • 17 DIV 5 gives 3, the whole-number quotient.
  • 17 MOD 5 gives 2, the remainder.

Five fits into 17 three times, leaving 2. A whole number is even when number MOD 2 == 0, because division by 2 leaves no remainder.

Read data and show results

INPUT name receives a value and stores it in name. OUTPUT shows a result. Quotation marks distinguish literal text from variable names. If name holds "Mia", then OUTPUT "Hello ", name shows "Hello Mia". But OUTPUT "name" shows the word "name".

Values also have types. An integer is a whole number; a decimal number can have a fractional part. A string is text. A Boolean is true or false. The number 7 can take part in arithmetic; the string "7" is text.

Follow a complete sequence

This algorithm finds a rectangle's area:

START
INPUT length
INPUT width
area ← length * width
OUTPUT area
END

With inputs 6 and 4, the calculation stores 24 in area. Only then does the output line show 24. An input must be stored before a later line uses it. The name area also makes the final output easier to understand than a name such as x.

Key Takeaways

  • Assignment calculates the right side, then stores it on the left.
  • A comparison tests values and returns true or false.
  • DIV gives a whole-number quotient; MOD gives a remainder.
  • Quotation marks make an output literal text.
  • Variables must receive values before those values are used.
2

Draw and follow flowcharts

Flowcharts make an algorithm’s possible paths visible. Learn what each shape means, then follow its arrows through choices and repeated steps. A labeled decision shows which route a value takes; a returning arrow shows what repeats. Drawing these routes carefully helps you find missing actions and check exactly where an algorithm continues or stops.

2.1 Use the standard flowchart symbols

A flowchart shows an algorithm using shapes joined by arrows. Each shape tells you what kind of step happens there. Begin at Start and follow the arrowheads to read the algorithm.

Choose a shape for each step
SymbolShapeWhat goes inside
TerminatorOval or rounded rectangleStart or Stop
ProcessRectangleOne action or calculation
Input/outputParallelogramAn INPUT or OUTPUT instruction
DecisionDiamondA true-or-false question
Predefined processRectangle with an extra vertical line inside each sideA named sub-routine
ConnectorSmall circleA matching letter or number

A terminator marks the start or finish. Use one Start in the main flowchart. More than one Stop is possible, although joining paths before one Stop often makes reading easier.

A process box can hold total ← total + price or an action such as "Switch on the light". Keep one action in each box. An input/output shape needs its instruction written inside: its shape alone cannot tell you whether data comes in or goes out.

Give decisions two labeled exits

A diamond holds a question such as temperature < 18?. Its two exits are labeled Yes and No, or True and False. Follow the exit that matches the current value. With a temperature of 16, follow Yes. With a temperature of 18, follow No.

Putting the question in a rectangle hides its role as a decision. Leaving the exits unlabeled makes the reader guess which action each answer chooses.

Draw a jacket algorithm

Draw a Start terminator, then an input parallelogram containing INPUT temperature. Connect it to a diamond asking temperature < 18?.

  • The Yes arrow leads to OUTPUT "Wear a jacket".
  • The No arrow leads to OUTPUT "No jacket needed".

Both output steps use parallelograms. Join their arrows before the Stop terminator. The chart has six shapes: Start, input, decision, two outputs, and Stop. A person follows only one of the output paths on each run.

Connect longer plans clearly

A predefined process runs a named group of steps described elsewhere. A drawing robot might call drawSquare. The extra side lines distinguish this call from a single ordinary action.

Use connectors to continue a chart without a long or crossing line. A circle labeled A continues at the matching A circle. The label identifies one connection point; the arrowheads still show which way to travel.

Draw downward and left to right where possible. Put an arrowhead on every flow line. Every shape except Stop needs an outgoing line; Stop receives arrows and has none leaving it. Check each branch to its finish. A control system that keeps checking a sensor may deliberately loop continuously and have no Stop.

Key Takeaways

  • Shape and label together tell you what a flowchart step does.
  • A decision diamond has two labeled exits.
  • Arrowheads give the order, including the route through connectors.
  • A predefined-process box calls steps defined elsewhere.

2.2 Show decisions in flowcharts

Selection lets an algorithm choose a path. A decision diamond tests a condition, then its Yes and No arrows lead to different steps. The paths can join again before the algorithm continues.

Read the comparison exactly

A condition has a true-or-false answer. These operators compare values:

OperatorMeaning
==Equal to
!=Not equal to
<Less than
>Greater than
<=Less than or equal to
>=Greater than or equal to

When age is 13, age >= 13 is true. But age > 13 and age != 13 are false. Equality matters at a boundary, the point where the chosen path changes.

Turn a rule into branches

“Children under 12 pay 5; everyone else pays 8” needs the condition age < 12. Draw Start, INPUT age, and that decision. The Yes path sets price ← 5; the No path sets price ← 8. Join the paths before OUTPUT price, then finish at Stop.

Age 9 follows Yes and outputs 5. Age 12 follows No and outputs 8. Using <= would include 12 in the lower-price group and change the rule.

Build more than two outcomes

One diamond has two exits. To award three medal bands, connect decisions in a chain. First ask score >= 80?. Yes outputs "Gold". No leads to score >= 50?. That diamond's Yes path outputs "Silver"; its No path outputs "Bronze".

A score of 79 fails the first test and passes the second. A score of 80 passes the first test immediately. It never reaches the second diamond.

The conditions overlap, so their order matters. Asking score >= 50? first and awarding Silver would catch 85 there too. The Gold branch would never receive that score. Check the highest band first in this chain, or give each range both limits.

Put one decision inside another

A nested decision appears on one branch of another decision. Suppose the first asks whether it is raining. Only its Yes path asks whether a parent is home. That second decision chooses between getting a ride and taking an umbrella. The first No path leads straight to walking. There is no need to ask the second question on that path.

You can trace a nested chart by writing down only the questions actually reached. With rain and no parent home, the route answers Yes, then No, and chooses the umbrella action. With no rain, it answers only the first question. Testing every diamond regardless of the arrows would add an action from a path that was never chosen.

Combine related conditions

AND is true when both parts are true. OR is true when at least one part is true, including when both are true. NOT reverses a condition's truth value.

The condition age >= 13 AND age <= 19 accepts ages 13 through 19. With OR, every age passes: an age below 13 meets the second part, and an age above 19 meets the first. Use parentheses when grouping conditions helps show the intended meaning.

After drawing decisions, follow every exit. Each must lead to an action, a joining point, another decision, or Stop.

Key Takeaways

  • Check whether a boundary value belongs on the Yes or No path.
  • A chain checks later decisions only along the arrows that reach them.
  • Order overlapping conditions so the intended band is reached.
  • An inner decision runs only on the outer branch that contains it.
  • AND needs both parts true; OR needs at least one.
  • Every branch needs a route onward.

2.3 Show repetition in flowcharts

A backward arrow makes steps repeat. This is iteration, or a loop. A decision controls whether the flow goes around again or leaves the loop.

Repeat a fixed number of times

A count-controlled loop uses a counter. To output the numbers 1 through 5, connect these steps:

  1. A process sets count ← 1.
  2. A diamond asks count <= 5?.
  3. Its Yes exit leads to OUTPUT count.
  4. A process sets count ← count + 1.
  5. An arrow returns to the diamond.
  6. The diamond's No exit leads onward to Stop.

The initial assignment sits outside the returning path. The counter starts at 1 once, then changes to 2 after the first output. The final successful test uses 5. After outputting 5, the update makes the counter 6. The next test is false, so the algorithm stops.

If the arrow returned to count ← 1, the counter would restart on every pass. It would never reach the value needed to leave.

Repeat until an event happens

A condition-controlled loop does not need a known repeat count. Consider a password check. Input a password, then ask whether it equals "tiger7". The No exit outputs "Try again" and returns to the input. The Yes exit outputs "Welcome" and leaves.

Returning to the input matters. Returning only to the decision would test the same wrong password forever. New data must be read for the decision to change.

Place the test carefully

A test before the repeated actions can prevent them from running at all. A test after the actions allows at least one pass. In the password chart, the input happens before the first test, so a password is always entered at least once.

The arrows show whether a diamond controls selection or iteration. Two forward paths that join show selection. A path returning to an earlier step shows repetition.

Imagine changing the counting chart's starting value to 6. The first test count <= 5? is already false, so no number is output. If the output and update came before that first test, 6 would be displayed once. This is why moving a test across the body changes behavior, even when the same shapes appear in both charts.

Keep a running total

Set total ← 0 before a loop. Inside, read each number and use total ← total + number. For inputs 3, 5, 2, and 6, the total changes to 3, 8, 10, and 16.

Resetting total to 0 inside the returning path erases earlier additions. The final total would then be only the last number, 6. Initial values belong before the loop when they must be kept across passes.

Check that the loop can finish

A missing counter update leaves count at 1, so count <= 5 stays true. Changing the update to subtraction also fails: the counter moves farther below 5. Either mistake creates an infinite loop.

Loops intended to finish need a change that eventually reaches their exit. Some sensor-control loops run continuously on purpose. For a counting loop, also check the last pass: starting at 1 with < 5 outputs only 1 through 4. Using <= 5 includes 5 and prevents that off-by-one error.

Key Takeaways

  • The backward arrow identifies the repeated steps.
  • Initialize counters and totals before the returning path.
  • A test before the body allows zero passes; a test after allows at least one.
  • A loop intended to finish must eventually reach its exit.
  • Trace the first and last pass to check the repeat count.
3

Write algorithms in structured pseudocode

Structured pseudocode turns a plan into readable instructions. Write calculations in order, group choices with IF, and repeat steps with a suitable loop. Indentation shows which instructions belong together. You will also connect this text to flowcharts and use named procedures, so a longer plan stays clear while its decisions and repeats keep the intended behavior.

3.1 Write clear, structured pseudocode

Pseudocode describes an algorithm in short, structured lines. It looks like code, but it is written for people. You can check the logic without choosing a programming language.

Give each line one clear job

Use capital letters for keywords such as INPUT and OUTPUT. Put one instruction on each line. Begin a complete main algorithm with START and finish it with END. Use ← to store a value and comparison signs such as == or >= to test values.

“Get the numbers and work out the average” is not precise enough to trace. This version makes the inputs, calculation, and output visible:

START
INPUT a
INPUT b
INPUT c
average ← (a + b + c) / 3
OUTPUT average
END

The input lines store three values before the calculation uses them. The parentheses group the sum, so all three numbers are added before division.

With values 6, 9, and 12, the sum is 27 and the average is 9. Without parentheses, a + b + c / 3 divides only 12 by 3 before adding. It gives 19. Multiplication and division happen before addition and subtraction unless parentheses change that order.

Show blocks with indentation

An indented line starts farther to the right. Indent instructions inside a decision or loop. Their position shows which block they belong to:

START
INPUT temperature
IF temperature < 18 THEN
    OUTPUT "Wear a jacket"
ENDIF
OUTPUT "Ready"
END

The jacket output runs only if the condition is true. The "Ready" output comes after the block and runs on either path. A line's position can change when it runs, so keep indentation consistent.

Match opening and closing keywords
OpeningClosing
IF ... THENENDIF
FOR ... TO ...NEXT counter
WHILE ... DOENDWHILE
REPEATUNTIL condition
PROCEDURE nameENDPROCEDURE

The closing keyword marks where a block ends. A missing ENDIF can make it unclear which later actions belong to the decision. Indentation and closing keywords work together; one does not replace the other.

Read other styles without mixing them

Pseudocode has no single worldwide spelling system. Other styles may use = or := for assignment, PRINT for output, or ENDFOR to close a FOR loop. Read their meanings, then use one consistent style when writing an algorithm. Follow a course's style when it sets one.

A programming language needs extra details. For example, Python can use age = int(input()) to read typed text and convert it into a whole number. The pseudocode line INPUT age leaves that language detail aside. The plan still needs precise steps: a line such as "sort out the answer" cannot be checked.

Key Takeaways

  • Use one clear instruction per line.
  • Indent the instructions inside each block.
  • Match every block opening with its closing keyword.
  • Parentheses show which calculation happens first.

3.2 Write decisions with IF statements

An IF statement chooses which instructions run. Its condition must be true or false. Indentation makes the chosen block visible, and ENDIF shows where the decision ends.

Choose one block

An IF without ELSE runs its block only when the condition is true. When false, it skips to the line after ENDIF. An IF with ELSE chooses exactly one of two blocks:

START
INPUT age
IF age < 12 THEN
    price ← 5
ELSE
    price ← 8
ENDIF
OUTPUT price
END

For age 12, age < 12 is false. The ELSE block sets price to 8. The output comes after ENDIF, so either branch reaches it. Using ← inside the condition would confuse storing a value with testing it.

Choose among several bands

An ELSE IF chain checks conditions from top to bottom. It runs the first true block and skips the remaining choices:

START
INPUT score
IF score >= 80 THEN
    OUTPUT "Gold"
ELSE IF score >= 50 THEN
    OUTPUT "Silver"
ELSE
    OUTPUT "Bronze"
ENDIF
END

At 85, the first condition is true. The algorithm outputs "Gold" and leaves the chain. At 79, the first condition is false, so it checks the second and outputs "Silver". At 49, neither condition is true, so ELSE outputs "Bronze".

The highest band must come first in this chain. A first test of score >= 50 would catch 85 before it could reach Gold.

Distinguish a chain from separate tests

Separate IF statements each get their own test. If one tests score >= 80 and a later one tests score >= 50, a score of 85 passes both. It can produce two messages. Use a chain when the algorithm must choose one band; use separate tests when separate actions may both be needed.

Place one IF inside another

A nested IF sits inside a branch of an outer IF. Each needs its own ENDIF:

IF raining == TRUE THEN
    IF parentsHome == TRUE THEN
        OUTPUT "Get a ride"
    ELSE
        OUTPUT "Take an umbrella and walk"
    ENDIF
ELSE
    OUTPUT "Walk"
ENDIF

Only rain makes the inner test run. The inner ELSE deals with no parent being home. The outer ELSE deals with no rain. Indentation helps match each ELSE to its IF.

For a single action, nested tests can sometimes be joined. A club displays "Join" only when age is at least 13 and membership is current:

IF age >= 13 THEN
    IF member == TRUE THEN
        OUTPUT "Join"
    ENDIF
ENDIF

The same action can use IF age >= 13 AND member == TRUE THEN. Both tests must pass in either plan. This replacement would need more care if the inner false branch also had an action.

Combine tests and compare text

age >= 13 AND age <= 19 requires both limits. OR requires at least one true part, so it cannot replace AND for this range. NOT (age < 13) reverses the test and means age >= 13.

Text comparisons also need care. answer == "yes" is false for "Yes" because the capital letter differs. Changing the input to lowercase before testing can make these entries match.

In a flowchart, THEN follows the diamond's Yes arrow. ELSE follows No. The paths join at the point represented by ENDIF.

Key Takeaways

  • IF with ELSE runs exactly one of its two blocks.
  • An ELSE IF chain runs only its first true block.
  • Separate IF statements are tested independently.
  • Each nested IF needs its own ENDIF.
  • Text comparisons distinguish uppercase and lowercase letters.

3.3 Write loops with FOR, WHILE and REPEAT

Loops repeat a block of instructions. Choose the loop by asking whether the repeat count is already known, and whether the body must run at least once.

Count passes with FOR

A FOR loop manages a counter. With its default upward step of 1, both end values are included:

FOR i ← 1 TO 4
    OUTPUT i * 7
NEXT i

The counter takes the values 1, 2, 3, and 4. The outputs are 7, 14, 21, and 28. At NEXT, the counter changes automatically. Do not add another counter increase inside the body.

Without STEP, the counter increases by 1. The pass count is last value minus first value plus 1 when the range counts upward by 1. Thus 1 to 5 gives five passes, but 0 to 5 gives six.

FOR i ← 2 TO 10 STEP 2 visits 2, 4, 6, 8, and 10. FOR i ← 5 TO 1 STEP -1 visits 5, 4, 3, 2, and 1. The step gives the direction and size of each change.

Test before repeating with WHILE

A WHILE loop tests before each pass. It repeats while the condition is true and stops when it is false:

number ← 1
WHILE number < 20 DO
    number ← number * 3
ENDWHILE
OUTPUT number

The value changes from 1 to 3, then 9, then 27. The next test is false, so the output is 27. The test happens between passes; it does not interrupt multiplication when the value crosses 20. If the starting value already failed the test, the body would run zero times.

Test after repeating with REPEAT

A REPEAT ... UNTIL loop runs the body before testing. It stops when the UNTIL condition is true:

REPEAT
    INPUT score
UNTIL score >= 0 AND score <= 100

The input instruction receives at least one score. A score outside the range leads to another input. A score of 0 or 100 ends the loop because both endpoints are allowed. WHILE repeats on true; UNTIL stops on true.

Use FOR for a known number of marks or laps. Use WHILE when a condition decides whether another pass is needed. Use REPEAT when an action, such as asking for input, must happen first. Python has no REPEAT keyword; a WHILE structure can perform that job.

Calculate an average after repetition

This complete plan reads four values. The total begins once, grows on each pass, and is divided only after all four inputs:

START
total ← 0
FOR i ← 1 TO 4
    INPUT number
    total ← total + number
NEXT i
average ← total / 4
OUTPUT average
END

For inputs 4, 6, 8, and 10, the stored totals are 4, 10, 18, and 28. Dividing 28 by 4 gives an average of 7. Putting OUTPUT average after the loop displays one final result; placing a total output inside would display intermediate sums instead.

Count inputs that meet a rule

A loop can also count inputs meeting a condition. Keep that count separate from the counter that tracks every pass:

passes ← 0
FOR i ← 1 TO 5
    INPUT mark
    IF mark >= 50 THEN
        passes ← passes + 1
    ENDIF
NEXT i
OUTPUT passes

Marks 72, 45, 50, 38, and 91 produce 3 passes. The mark 50 counts because >= includes equality. The loop counter tracks all five entries; passes tracks only entries meeting the rule.

A finishing WHILE loop must change data used by its condition. Missing the update in a counting loop leaves the test true forever.

Key Takeaways

  • FOR includes both reachable endpoints and changes its own counter.
  • WHILE tests before the body and can run zero times.
  • REPEAT tests after the body and runs at least once.
  • UNTIL stops when its condition becomes true.
  • Initialize totals before the loop and update them inside.
  • An IF inside a loop can count only values meeting a rule.

3.4 Convert between flowcharts and pseudocode and use sub-routines

A flowchart and pseudocode can express the same algorithm. Converting between them changes the form of the plan while keeping the same actions, decisions, and repeat paths.

Translate the meaning of each shape
Flowchart stepPseudocode
Start or Stop terminatorSTART or END
Input/output parallelogramINPUT or OUTPUT
Process rectangleAssignment or action
Decision with forward branchesIF ... THEN ... ELSE ... ENDIF
Decision with a returning pathA loop
Predefined-process boxCALL name

Follow arrows from Start. At each diamond, inspect both routes. A returning route marks repetition. Two forward routes show selection. Indent the lines inside the corresponding block.

Keep the next input inside the loop

A password flowchart asks for input, tests it, and returns for another try after a wrong password. One translation is:

START
INPUT password
WHILE password != "tiger7" DO
    OUTPUT "Try again"
    INPUT password
ENDWHILE
OUTPUT "Welcome"
END

The first input supplies the value for the first test. The input inside the loop replaces a wrong attempt. Removing that second input would keep testing the same value.

Turn blocks back into arrows

Draw a shape for every action, input, output, and test. Closing words such as ENDIF, NEXT, and ENDWHILE tell you how to connect arrows. They do not need their own action boxes.

For an IF, label the diamond's Yes and No exits and join the paths where ENDIF occurs. For a WHILE, the test comes first and the body's last arrow returns to it. For REPEAT, the body comes first and the test's false route returns to the body.

Expand a FOR into initialization, test, body, update, and a returning arrow. For FOR i ← 5 TO 1 STEP -1, initialize 5, test i >= 1, run the body, then subtract 1. With the default upward step, add 1 and test i <= the final value.

Trace one boundary in both forms after converting. A countdown from 5 through 1 should output 1 before leaving. On the next return, its counter is 0 and i >= 1 is false. If the converted diamond tested i > 1, the text and drawing would differ: the drawing would miss the final 1.

Name a reusable group of steps

A sub-routine, also called a procedure, groups instructions under a name. Define it once, then use CALL wherever it should run:

PROCEDURE drawSquare
    FOR side ← 1 TO 4
        MOVE FORWARD 50
        TURN RIGHT 90
    NEXT side
ENDPROCEDURE

CALL drawSquare runs the four movement-and-turn pairs. When it finishes, execution returns to the line after the call. Calling it three times draws 12 sides. Defining it without calling it draws nothing.

In a flowchart, put drawSquare in a predefined-process box with extra vertical side lines. Show its detailed steps in a separate chart, beginning with a terminator containing the procedure name.

A named procedure keeps the main plan readable and allows repeated steps to be checked in one place. A supplied routine, such as one that plays a sound, can also be called by name.

For a main algorithm that should play a sound before drawing, put CALL playSound first and CALL drawSquare next. Each call completes before the following instruction begins. Their definitions can be kept separately, so the call order in the main plan stays easy to see.

Key Takeaways

  • Follow the arrows to identify a branch or a loop before translating.
  • Closing keywords control connections and do not need process boxes.
  • A FOR flowchart must use the counter change and test matching its step.
  • A procedure runs when called, then returns to the next instruction.
4

Trace and test algorithms by hand

An algorithm can look sensible and still give the wrong result. Tracing follows its actual steps and records changing values. Testing compares those results with the problem’s rules. Use both to predict outputs, identify the algorithm’s purpose, and find the first faulty step. Carefully chosen boundary inputs often reveal errors that ordinary inputs miss.

4.1 Trace an algorithm with a trace table

Hand tracing means following an algorithm on paper, one instruction at a time. It is also called a dry run or desk check. A trace table records values so you can see what changes during the run.

Set up the table

Make a column for every variable and another for output. You can add condition columns to record true or false. Enter starting values, then follow the instructions in the order they actually run.

Add a row whenever a value changes or a new pass begins. Some tables leave unchanged cells blank; a blank then means no new value was written. A blank before any assignment means the variable has not received a value. Use one convention clearly so these meanings are not confused.

Only change the variable named on the left of the current assignment. Use values already stored, not values from lines that have yet to run. Record output only when an OUTPUT instruction is reached.

Trace a running total
START
total ← 0
FOR count ← 1 TO 4
    total ← total + count
NEXT count
OUTPUT total
END

The table below leaves unchanged cells blank. Read their latest value above. The output column stays empty until the output line runs.

Instruction reachedcounttotalOutput
total ← 0—0
First counter value1
Add count1
NEXT count2
Add count3
NEXT count3
Add count6
NEXT count4
Add count10
Final NEXT; leave loop5
OUTPUT total10

On the second pass, the stored total 1 is increased by the current count 2. That makes 3. On the third pass, 3 increases by 3 to make 6. Do not reset the total on each pass.

The final counter value 5 lies beyond the FOR range, so no fifth addition occurs. Its value can change without becoming an output. Keeping separate columns prevents the loop counter from being mistaken for the total the algorithm is asked to display.

Record tests and input changes

For number ← 1 followed by a WHILE loop multiplying by 3 while number < 20, test the current value each time. Values 1, 3, and 9 pass. Value 27 fails, so the body ran three times.

For a loop counting marks of at least 50, enter each mark when its input line runs. Marks 72, 45, 50, 38, and 91 give pass counts 1, 1, 2, 2, and 3. A false condition leaves the count unchanged.

See why assignment order matters

To swap a holding 3 with b holding 7, save one original value:

temp ← a
a ← b
b ← temp

After the first line, temp holds 3. The second stores 7 in a. The third stores the saved 3 in b. Without temp, a ← b followed by b ← a leaves both variables holding 7. The original 3 was overwritten.

A flowchart is traced the same way. Keep your place on the current shape, update the table at each process, and use current values to choose each decision's exit. In a FOR loop, the counter changes at NEXT, after the body, so keep that update in its proper place.

Key Takeaways

  • A trace follows the actual path one instruction at a time.
  • Use current values and change only what the current instruction changes.
  • Record output only when the output instruction runs.
  • A temporary variable can preserve a value before it is overwritten.

4.2 Predict, test and correct algorithms

A trace predicts what an algorithm does for one input. Testing compares that result with what the problem requires. A useful test can expose a wrong boundary, a missing branch, or a loop that ends too early.

Predict output and find purpose

Trace several different inputs to identify an algorithm's purpose. A decision that outputs a when a > b, and otherwise outputs b, gives 8 for inputs 3 and 8. It gives 9 for 9 and 2, and 5 for 5 and 5. Its purpose is to output the larger value, including the shared value when both are equal.

Describe that general job. “It outputs 8” describes only one run.

Work out the expected result first

The expected output comes from the problem's rules. The actual output comes from tracing or running the algorithm. Work out the expectation before checking the algorithm, so a faulty result does not become your answer key.

If expected and actual results differ, trace the steps to find the cause. Check the expected result too: a mistaken calculation in the test plan can make a correct algorithm appear wrong.

Choose tests that reveal different problems
Data typeWhat it checksExample for a score from 0 to 100
NormalA typical allowed value65
BoundaryValues at or beside a limit0, 100, and values beside a band change
InvalidA value to reject-5, 105, or "ten"

Boundary data is also called extreme data in some courses. Invalid data may be called erroneous data. For bands starting at 50 and 80, useful tests include 49, 50, 79, and 80. They check the exact points where messages change.

A test plan records the input, data type, expected output, actual output, and pass or fail. Number the tests so a failed case is easy to find. Record a pass only when actual and expected outputs agree.

Suppose a medal algorithm mistakenly uses score > 80 for Gold, with Silver beginning at 50. A short test plan exposes the wrong comparison:

TestInputTypeExpectedActualResult
185NormalGoldGoldPass
280BoundaryGoldSilverFail
379BoundarySilverSilverPass

The failure at 80 points to equality at the Gold threshold. Passing 85 alone would not find it.

Locate and repair a logic error

A logic error lets the steps run but produces the wrong behavior. This countdown should include 1:

count ← 5
WHILE count > 1 DO
    OUTPUT count
    count ← count - 1
ENDWHILE

It outputs 5, 4, 3, and 2. When count reaches 1, the condition is false before output can run. Change it to count >= 1 or count > 0. Retest the first and last passes to check the repair.

Debugging means finding and fixing errors. Other causes include a wrong initial value, steps in the wrong order, and a total reset inside a loop.

Check a changed rule

Suppose ticket prices gain a new band: people aged 65 and over pay 6. On the No exit of age < 12, add age >= 65. Its Yes path sets 6; No sets 8. Check 64 and 65, plus the child-price boundary, to make sure the new branch works with the old ones.

Test every decision exit and loops with zero, one, and many passes where possible. A few successful cases can still leave another path wrong. Fix the faulty rule, then repeat earlier tests to check the change.

Key Takeaways

  • Expected results come from the problem; actual results come from the algorithm.
  • Use normal, boundary, and invalid test data.
  • Trace a failure to the first step that causes the wrong result.
  • Retest earlier cases after a repair.
  • Testing different paths reveals errors that one example can miss.
5

Design and compare algorithms

A new problem may need several structures working together. Start with its data and rules, build a plan, and check it with test cases. Then compare possible solutions by the results they produce and the work they require. A useful choice also considers who must read the plan and which inputs it must handle, so speed is judged alongside correctness and clarity.

5.1 Design an algorithm for a new problem

Design starts with the job an algorithm must do. Write down the inputs, required outputs, and rules before choosing instructions. Then split the problem into parts you can plan and test.

Move from a problem to a plan

Use an IPO chart to identify data and results. Choose sequence for ordered actions, selection for choices, and iteration for repeated work. Write the plan as a flowchart or pseudocode, trace it, then improve the steps that fail a test.

A flowchart suits a short control plan with visible branches. Pseudocode is easier to change when there are many instructions. You can convert between them while keeping the same logic.

Design a change-giving algorithm

Suppose coins have values 100, 50, 20, 10, and 5 cents. The input is an amount to pay. The outputs are the coin values handed over. Use the largest available coin that still fits, subtract it, and try again before moving to the next smaller value.

For the 100-cent coin, one block is:

WHILE amount >= 100 DO
    OUTPUT 100
    amount ← amount - 100
    coins ← coins + 1
ENDWHILE

Set coins ← 0 before any coin blocks. Repeat the same pattern for 50, 20, 10, and 5. Each block can give its coin several times; an IF would give it only once.

For 145 cents, give 100 and leave 45. Skip 50. Give 20 twice, leaving 5, then give 5. The result is four coins. For an amount of 0, every coin loop runs zero times, so no coins are given.

Handle amounts that cannot be paid

The amount must be a nonnegative whole number of cents. With 5 as the smallest coin, it must also be a multiple of 5. Otherwise a remainder would be left unpaid. The complete plan below accepts whole-number input and checks the other rules before giving coins:

START
INPUT amount
IF amount < 0 OR amount MOD 5 != 0 THEN
    OUTPUT "Cannot pay this amount exactly"
ELSE
    coins ← 0
    WHILE amount >= 100 DO
        OUTPUT 100
        amount ← amount - 100
        coins ← coins + 1
    ENDWHILE
    WHILE amount >= 50 DO
        OUTPUT 50
        amount ← amount - 50
        coins ← coins + 1
    ENDWHILE
    WHILE amount >= 20 DO
        OUTPUT 20
        amount ← amount - 20
        coins ← coins + 1
    ENDWHILE
    WHILE amount >= 10 DO
        OUTPUT 10
        amount ← amount - 10
        coins ← coins + 1
    ENDWHILE
    WHILE amount >= 5 DO
        OUTPUT 5
        amount ← amount - 5
        coins ← coins + 1
    ENDWHILE
ENDIF
END

The ELSE is essential: an invalid amount must not continue into those blocks. An amount of 147 leaves 2 cents that these coins cannot pay.

Repeated coin blocks suggest a possible later improvement: one reusable routine for each chosen coin value. The simple repeated blocks still make the complete process easy to trace.

Combine decisions and repetition in a game

A guessing game needs input repeatedly, but its repeat count is unknown:

START
secret ← 42
REPEAT
    INPUT guess
    IF guess > secret THEN
        OUTPUT "Too high"
    ELSE IF guess < secret THEN
        OUTPUT "Too low"
    ENDIF
UNTIL guess == secret
OUTPUT "Correct"
END

Guesses 50, 30, and 42 produce "Too high", "Too low", and "Correct". The correct guess reaches neither message inside the IF. The UNTIL test then ends the loop, and the final output runs once.

Key Takeaways

  • Identify inputs, outputs, and rules before writing the steps.
  • Choose constructs to match choices and repetition in the problem.
  • Keep invalid input away from the steps that require valid data.
  • Trace zero values and boundaries as well as typical cases.

5.2 Compare algorithms that solve the same problem

Two algorithms can solve the same problem with different steps. Comparing them means checking what they get right, how much work they do, and how easy their plans are to understand.

Compare four features
FeatureQuestion to ask
CorrectnessDoes it give the required result for every valid input?
EfficiencyHow many operations or loop passes does it need?
ClarityIs it easy to follow, check, and change?
GeneralityWhich range of inputs can it handle?

Check correctness before choosing a fast method. A quick wrong answer does not solve the problem. The valid input range matters: a method that works only for positive values may fail when negatives are allowed.

Count the work as inputs grow

To add whole numbers from 1 through n, a loop starts at zero and adds each value. It performs n additions. A formula uses total ← n * (n + 1) / 2, requiring one addition, one multiplication, and one division.

For n equal to 100, both produce 5,050. The loop makes 100 additions, while the formula makes three arithmetic operations. At 1,000, both produce 500,500, but the loop now needs 1,000 additions. The formula still uses three operations.

These counts compare the stated arithmetic work. A loop also has counter and condition steps. Use the same counting rule for both algorithms. Timing one run on a computer mixes the algorithm with the machine's speed, and one small test says little about larger inputs.

Check the full input range

One even-number algorithm repeatedly subtracts 2 while the number is greater than 1. It then reports even only when the remaining value is 0. For 1,000, this needs 500 subtractions. Testing number MOD 2 == 0 needs one remainder operation.

The subtraction method also fails for -4. The loop never runs, and -4 is not 0, so it reports "odd". Yet -4 is even. This is both an efficiency problem and a generality problem when negative integers are valid inputs.

Challenge an apparently good method

Largest coin first gives the fewest coins for values 100, 50, 20, 10, and 5. Its success depends on the coin set. With coins of 1, 3, and 4, the same rule pays 6 as 4, 1, and 1. That is three coins. Two 3-cent coins pay the same amount with only two coins.

This single counterexample is enough to reject the claim that largest coin first always uses the fewest coins for every coin set. It still pays the full amount in this example; the failure concerns the requested minimum number of coins.

Balance speed and readability

A short written loop can execute thousands of times. A longer-looking plan can do less work. Written length is not an operation count.

Clarity matters when people must check or change an algorithm. Descriptive variable names and a short explanation can make a fast formula easier to follow. Choose among correct methods by the task: very large inputs may favor fewer operations, while a shared beginner project also needs readable steps.

Key Takeaways

  • Compare correctness, efficiency, clarity, and generality.
  • Count operations or passes with the same rule for both methods.
  • Check how the work grows as the input grows.
  • One counterexample can show that a general claim is false.
  • Written length does not tell you how much work an algorithm executes.

Flowcharts and Pseudocode examples

5 Walkthroughs

1

Turn a task into precise steps

12 steps
Plan the data and instructions, then follow how assignments change stored values.
  1. 1
    IntroductionPlan before coding

    Imagine a program that tells a robot what to do. The robot needs precise instructions, including where to begin and when to stop. Start by identifying the data and result, then put the actions in order.

    We will plan an average-score algorithm and follow the values it stores. A flowchart or pseudocode can hold that plan before it becomes a program.

  2. 2
    ExplanationGive each step one meaning

    An algorithm is a finite, ordered set of precise steps. “Repeat a few times” is unclear because readers may choose different counts. “Repeat 3 times” has one meaning.

    A program writes the plan in a language a computer can run. Flowcharts and pseudocode describe the logic for people to inspect and share.

  3. 3
    ExampleSeparate data, work, and result

    For an average of three scores, the inputs are 72, 85, and 90. Processing adds them to make 247, then divides by 3. The output is the average, 82.3 to one decimal place.

    An IPO chart puts those three roles in separate columns. The average is the result we want; it is not another input to type.

  4. 4
    ConnectionChoose how steps are controlled

    The average calculation uses sequence: read the scores, calculate, then output. A decision awarding a message uses selection. Asking for several scores in a loop uses iteration.

    Order still matters inside a larger plan. An output placed before its calculation cannot show the newly calculated result.

  5. 5
    ChallengePlan a garden task

    A program receives a garden's length and width and displays its perimeter. What belongs in the process part of its IPO chart?

    ---reveal---

    Add the length and width, then multiply the sum by 2. The dimensions are inputs; the perimeter is output. The process describes how to obtain that result, not another measurement to enter.

  6. 6
    AnalogyGive a value a name

    Think of a variable as a labeled place for a value. The label stays, but its contents can be replaced. A name such as total makes the value's purpose clear.

    total ← 5 stores 5 there. The arrow points toward the variable receiving the value. Nothing is displayed yet; output needs its own instruction.

  7. 7
    ExampleReplace the old value

    Now follow total ← total + 3. The right side uses the stored 5 and calculates 8. Assignment then replaces 5 with 8 in total.

    By contrast, total == 8 asks a true-or-false question and changes nothing. The assignment arrow stores a value; the equality comparison tests it.

  8. 8
    TipRead names and literal text

    Quotation marks make output literal text. If name holds "Mia", OUTPUT name displays "Mia". OUTPUT "name" displays the four letters "name".

    Numbers and strings also differ: 7 is a number, while "7" is text. Integers, decimals, strings, and Booleans tell us what kind of value is stored.

  9. 9
    ExampleUse quotient and remainder

    DIV and MOD describe different parts of whole-number division. 17 DIV 5 gives 3 because three full groups of 5 fit. 17 MOD 5 gives the leftover 2.

    For an even-number test, use number MOD 2 == 0. An even integer divides into groups of 2 with no remainder.

  10. 10
    ChallengeFollow a copied value

    A plan starts with a ← 4 and b ← 9. It then runs a ← b followed by b ← b + 2. What values do a and b now hold?

    ---reveal---

    a holds 9 and b holds 11. The first assignment copies the current 9 into a. Changing b afterward does not change the value already copied into a.

  11. 11
    ChallengeConnect the plan to its output

    A trip plan reads distance as 24 and speed as 6. It calculates time ← distance / speed, then runs OUTPUT "time". What does it display, and how can it display the calculated value?

    ---reveal---

    It displays "time". Remove the quotation marks: OUTPUT time displays 4. The calculation stores a value; output decides what the user sees.

  12. 12
    RecapCheck the data’s route

    To inspect a short plan, locate its inputs and the result it should produce. Check that calculations happen after their inputs and before their outputs.

    Read each assignment using current values. Then read each output literally: a variable name displays its contents, while quoted text displays exactly those characters.

2

Follow choices and loops in a flowchart

16 steps
Read symbol meanings and trace the routes through decisions and repeated actions.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionRead the route through a chart
  2. 2
    ExplanationMatch a shape to its job
  3. 3
    ExplanationRead calls and connections
  4. 4
    ExampleDraw a jacket choice
  5. 5
    ChallengeRepair an unlabeled diamond
  6. 6
    ExampleCheck equality at the edge
  7. 7
    ExampleFollow a chain of bands
  8. 8
    Key InsightCombine the conditions of a range
  9. 9
    ChallengeChoose the first diamond
  10. 10
    ExampleBuild a returning path
  11. 11
    ExampleTrace the final pass
  12. 12
    TipLet the next pass change the data
  13. 13
    ExampleCarry a total through the loop
  14. 14
    ChallengeFix the wrong repeat count
  15. 15
    ChallengeKeep a repeated decision inside the loop
  16. 16
    RecapInspect every arrow
3

Build readable decisions, loops, and calls

19 steps
Write structured pseudocode and preserve its behavior when converting to flowcharts.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionMake the blocks visible
  2. 2
    ExampleWrite a precise sequence
  3. 3
    ChallengeFind the hidden order change
  4. 4
    TipShow where a block ends
  5. 5
    ExampleChoose one of two actions
  6. 6
    ExplanationLet the first true band win
  7. 7
    ExampleFollow a decision inside a decision
  8. 8
    ChallengeRepair a range test
  9. 9
    ExampleLet FOR manage its counter
  10. 10
    Key InsightUse a different step
  11. 11
    ExampleTrace a WHILE threshold
  12. 12
    ExplanationRead UNTIL as a stopping rule
  13. 13
    ExampleAdd only the values that qualify
  14. 14
    ChallengeCount after the change
  15. 15
    ConnectionTranslate block boundaries into arrows
  16. 16
    ExampleCall a named group of steps
  17. 17
    ChallengeConvert a countdown
  18. 18
    ChallengePut a call inside a repeated choice
  19. 19
    RecapRead the structure before tracing
4

Trace a plan and find its first wrong step

12 steps
Record changing values, predict output, and choose tests that reveal logic errors.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionCompare the steps with the job
  2. 2
    ExplanationPrepare a trace table
  3. 3
    ExampleFollow the first two passes
  4. 4
    ExampleFinish the trace before output
  5. 5
    TipPreserve a value before replacing it
  6. 6
    ChallengeTrace only the chosen branch
  7. 7
    ExplanationDescribe purpose beyond one run
  8. 8
    ExampleChoose revealing test inputs
  9. 9
    ExampleFind the missing final output
  10. 10
    ChallengeChoose a test for a changed boundary
  11. 11
    ChallengeDiagnose a total that restarts
  12. 12
    RecapUse a failure to improve the plan
5

Design a solution and compare its work

12 steps
Build a coin-giving plan, test its input rules, and evaluate alternative algorithms.

Save this lesson to follow every Walkthrough step by step.

  1. 1
    IntroductionDefine what success means
  2. 2
    ExplanationSplit the coin task
  3. 3
    ExampleTrace the payment
  4. 4
    TipKeep invalid amounts out
  5. 5
    ChallengeDesign one repeated coin block
  6. 6
    ConnectionChoose a loop for unknown attempts
  7. 7
    ExplanationCompare the right features
  8. 8
    ExampleCount work for a larger input
  9. 9
    ExampleFind an input the method misses
  10. 10
    ChallengeTest the minimum-coin claim
  11. 11
    ChallengeChoose between two correct plans
  12. 12
    RecapJudge against the actual task

Flowcharts and Pseudocode practice questions

40 Practice Questions in 4 sets

Set 1: Connect branches, loops, and tests10 Practice Questions

Question 1 of 10

A plan must read a distance and a time, calculate speed from them, then display speed. What must happen before the speed calculation?
  1. The speed must be displayed first.
  2. Both input values must be stored.
  3. Only the distance must be stored.
  4. The time must be compared with speed.
Show answerHide answer
Answer: B
The calculation depends on both distance and time, so both inputs must be available first. Reading distance alone leaves a required value missing. An output before the calculation also cannot display the newly calculated speed; sequence must respect these dependencies.

Question 2 of 10

A flowchart continues at a circle labeled R in another column. What should its matching connection point show, and how is the direction indicated?
  1. S, with direction shown by arrowheads.
  2. R, with direction shown by circle size.
  3. S, with direction shown by circle size.
  4. R, with direction shown by arrowheads.
Show answerHide answer
Answer: D
Matching connector labels identify the same connection point, so the second circle must also show R. Arrowheads show the direction of travel through it. Different labels would name different connections and would not tell the reader where this particular route continues.

Question 3 of 10

A diamond tests age >= 11 AND age <= 15?. For ages 10, 11, and 16 in that order, what exits are followed?
  1. No, Yes, No
  2. Yes, Yes, No
  3. No, No, Yes
  4. Yes, Yes, Yes
Show answerHide answer
Answer: A
Age 10 fails the lower limit, 11 meets both limits, and 16 fails the upper limit. AND requires both comparisons to be true at the same time. Accepting all three would use the meaning of OR, which lets either comparison alone make the condition true.

Question 4 of 10

How many times does OUTPUT n run?

n ← 18
WHILE n < 18 DO
    OUTPUT n
    n ← n + 1
ENDWHILE
  1. 1
  2. 17
  3. 0
  4. 18
Show answerHide answer
Answer: C
The starting test is 18 < 18, which is false. WHILE checks before entering its body, so the output and update are both skipped. One output would fit a body that runs before its test, as in REPEAT, but not this WHILE structure.

Question 5 of 10

What is output for inputs 4, 7, 2, and 9?

total ← 0
FOR i ← 1 TO 4
    INPUT n
    IF n MOD 2 != 0 THEN
        total ← total + n
    ENDIF
NEXT i
OUTPUT total
  1. 2
  2. 22
  3. 16
  4. 6
Show answerHide answer
Answer: C
The condition selects numbers with a nonzero remainder on division by 2, so it adds 7 and 9. The even inputs 4 and 2 leave the total unchanged, giving 16. The result 2 would count the selected inputs, but the assignment adds their values instead.

Question 6 of 10

A main algorithm runs CALL chime, then OUTPUT "Done". The procedure outputs "Ring" twice and finishes. What is the output order?
  1. "Done", "Ring", "Ring"
  2. "Ring", "Ring", "Done"
  3. "Ring", "Done", "Ring"
  4. "Done" only
Show answerHide answer
Answer: B
The call runs the entire procedure before the main algorithm continues. Both "Ring" outputs therefore appear before "Done". Placing "Done" between them would return from the procedure before it has finished, which a normal procedure call does not do.

Question 7 of 10

What pair is output?

a ← 6
b ← 11
temp ← a
a ← b - 2
b ← temp + a
OUTPUT a, b
  1. 9, 17
  2. 9, 20
  3. 11, 15
  4. 9, 15
Show answerHide answer
Answer: D
temp preserves 6, and a ← b - 2 stores 9 in a. The last assignment uses the saved 6 and current 9 to store 15 in b. Getting 20 would use the old 11 instead of the new value of a in that final calculation.

Question 8 of 10

A field accepts whole-number ages from 9 through 16. What kind of test data is an input of 12?
  1. Normal data.
  2. Boundary data.
  3. Invalid data.
  4. Expected output.
Show answerHide answer
Answer: A
Twelve is an allowed value away from either endpoint, so it is normal test data. The allowed endpoints are 9 and 16; those would check boundaries. A value does not become boundary data just because it belongs to the accepted range.

Question 9 of 10

A library plan accepts a whole-number loan length from 1 through 21 days. It prints an error for 0 but still calculates and displays a return date. How should the plan control that calculation?
  1. Put it before the input is received.
  2. Put it inside the valid-input branch.
  3. Put it after both branches have joined.
  4. Put it inside the invalid-input branch.
Show answerHide answer
Answer: B
The return-date calculation requires a valid loan length, so only the valid-input route should reach it. An error message alone does not prevent later instructions from running. Placing the calculation after the branches join would keep the same failure for 0.

Question 10 of 10

Two algorithms correctly add 1 through n for positive integers. A adds every value in a loop; B uses n * (n + 1) / 2. Counting arithmetic only, what are their counts at n = 250 and n = 500?
  1. A: 250 then 500; B: 3 then 6.
  2. A: 250 then 500; B: 250 then 500.
  3. A: 3 then 3; B: 250 then 500.
  4. A: 250 then 500; B: 3 then 3.
Show answerHide answer
Answer: D
A performs one addition for each number, so its count rises from 250 to 500. B uses one addition, one multiplication, and one division at either size. Doubling its count to 6 would assume its work grows with the input even though the expression stays the same.
Set 2: Read the steps and follow the values10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A program receives the number of teams and the number of players on each team. It displays the total player count. What is the output?
  1. The number of teams entered.
  2. The number of players per team.
  3. The total number of players.
  4. The multiplication instruction.
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

What value does points hold after points ← 13 followed by points ← points - 4?
  1. 9
  2. 13
  3. 4
  4. 17
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

What flowchart shape should contain OUTPUT "Door open"?
  1. A process rectangle.
  2. A decision diamond.
  3. A terminator oval.
  4. A parallelogram.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A chart tests tickets < 6?. Yes sets fee ← 2; No sets fee ← 0. Both paths lead to OUTPUT fee. What is displayed when tickets is 6?
  1. 2
  2. 0
  3. 6
  4. 8
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

A chart sets count ← 3, then tests count <= 7?. Yes outputs count, adds 1, and returns to the test. No stops. How many values are output?
  1. 4
  2. 5
  3. 7
  4. 8
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

What keyword closes a pseudocode block opened by WHILE ... DO?
  1. UNTIL
  2. NEXT
  3. ENDWHILE
  4. ENDIF
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

What message is output when badges is 7?

IF badges >= 10 THEN
    OUTPUT "Leader"
ELSE IF badges >= 5 THEN
    OUTPUT "Helper"
ELSE
    OUTPUT "Member"
ENDIF
  1. "Helper"
  2. "Leader"
  3. "Member"
  4. "Leader", then "Helper"
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

What values does this loop output?

FOR i ← 3 TO 9 STEP 3
    OUTPUT i
NEXT i
  1. 3, 4, 5, 6, 7, 8, 9
  2. 3, 6
  3. 6, 9, 12
  4. 3, 6, 9
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

What is the final output?

x ← 2
FOR i ← 1 TO 3
    x ← x + i
    IF x >= 5 THEN
        x ← x - 1
    ENDIF
NEXT i
OUTPUT x
  1. 6
  2. 5
  3. 7
  4. 8
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A machine dispenses stickers until a user enters 0. It must ask for a quantity at least once. What loop structure fits the input step?
  1. FOR with a fixed repeat count.
  2. IF with two forward branches.
  3. REPEAT with an UNTIL test.
  4. A sequence with one input only.
Show answerHide answer

Save this lesson to see this answer.

Set 3: Trace changes and diagnose failures10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

A canteen plan reads portions ordered, calculates the ingredients needed, checks stock, and prints a shopping list. How can decomposition split this job into two useful parts?
  1. Read portions; repeat reading without calculating.
  2. Print the list; calculate needs after printing.
  3. Check stock; omit calculating ingredient needs.
  4. Calculate ingredient needs; compare needs with stock.
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

What flowchart symbol represents CALL playTune, where playTune is defined elsewhere?
  1. A rectangle with extra vertical side lines.
  2. A parallelogram for incoming or outgoing data.
  3. A small circle with a connection label inside.
  4. A diamond with labeled Yes and No exits.
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A chart initializes count ← 2 and total ← 0. It tests count <= 6?; Yes adds count to total, increases count by 2, and returns. No outputs total. What is output, and why does the next test leave?
  1. 12; the counter becomes 6.
  2. 12; the counter becomes 8.
  3. 6; the counter becomes 8.
  4. 20; the counter becomes 10.
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

An algorithm runs OUTPUT "Low" inside IF level < 3 THEN ... ENDIF, then runs OUTPUT "Checked" after ENDIF. What is output for level 5?
  1. "Low" only
  2. "Low", then "Checked"
  3. No message
  4. "Checked" only
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

What messages are output for score = 86?

IF score >= 75 THEN
    OUTPUT "Top"
ENDIF
IF score >= 40 THEN
    OUTPUT "Ready"
ELSE
    OUTPUT "Retry"
ENDIF
  1. "Top" only
  2. "Ready" only
  3. "Top", then "Ready"
  4. "Top", then "Retry"
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

What is output for successive inputs 5, 12, and 8?

total ← 0
REPEAT
    INPUT n
    total ← total + n
UNTIL n >= 10
OUTPUT total
  1. 5
  2. 17
  3. 25
  4. 12
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A chart reads entry, tests entry == 0?, and stops on Yes. No outputs "Again" and returns to read a new entry. After the initial input, what WHILE condition matches that route?
  1. entry != 0
  2. entry == 0
  3. entry > 0
  4. entry < 0
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

What is the final output for inputs 3, 8, and 5?

best ← 0
FOR i ← 1 TO 3
    INPUT n
    IF n > best THEN
        best ← n
    ENDIF
NEXT i
OUTPUT best
  1. 3
  2. 5
  3. 8
  4. 16
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A plan should total four inputs but gives only the last input. The loop reads each number, sets total ← 0, then adds the number. Moving the initialization repairs it. What expected outputs test both the old failure and the all-zero case?
  1. Inputs 2, 4, 1, 7 → 7; zeros → 0.
  2. Inputs 2, 4, 1, 7 → 14; zeros → 4.
  3. Inputs 2, 4, 1, 7 → 7; zeros → 4.
  4. Inputs 2, 4, 1, 7 → 14; zeros → 0.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

Two correct plans do the same number of arithmetic operations for all valid inputs. One uses names such as remainingSeats; the other uses unexplained single letters. What feature is most directly improved by descriptive names?
  1. Clarity.
  2. Efficiency.
  3. Generality.
  4. Correctness.
Show answerHide answer

Save this lesson to see this answer.

Set 4: Apply the rules to new plans10 Practice Questions

Save this lesson to see every answer and practice every set.

Question 1 of 10

What is the value of 29 MOD 6?
  1. 4
  2. 5
  3. 6
  4. 23
Show answerHide answer

Save this lesson to see this answer.

Question 2 of 10

What is output?

a ← 5
b ← 8
a ← a + b
b ← a - b
a ← a - b
OUTPUT a, b
  1. 5, 8
  2. 13, 5
  3. 8, 5
  4. 8, 3
Show answerHide answer

Save this lesson to see this answer.

Question 3 of 10

A chart reads points = 11 and bonus = true. Its first diamond tests bonus == TRUE?; Yes adds 5 to points, and No leaves it unchanged. The paths join at points >= 10?, which sets level to 2 on Yes and 1 on No. A final diamond tests points >= 14?; Yes adds 1 to level, while No leaves it unchanged. What does OUTPUT level display?
  1. 3
  2. 1
  3. 2
  4. 16
Show answerHide answer

Save this lesson to see this answer.

Question 4 of 10

A loop starts at count ← 1 and total ← 0. While count <= 5, it adds count to total and increases count by 2. It should add every integer from 1 through 5. What does it currently total, and what update repairs it?
  1. 15; change the increase to 1.
  2. 9; change the increase to 3.
  3. 15; change the increase to 3.
  4. 9; change the increase to 1.
Show answerHide answer

Save this lesson to see this answer.

Question 5 of 10

For a = 10 and b = 4, what does result ← a + b * 2 store?
  1. 28
  2. 24
  3. 18
  4. 14
Show answerHide answer

Save this lesson to see this answer.

Question 6 of 10

What messages are output for age = 10 and member = true?

IF age < 14 THEN
    IF member == TRUE THEN
        OUTPUT "Junior member"
    ELSE
        OUTPUT "Junior guest"
    ENDIF
ENDIF
IF member == TRUE THEN
    OUTPUT "Member desk"
ENDIF
  1. "Junior member", then "Member desk"
  2. "Junior member" only
  3. "Junior guest", then "Member desk"
  4. "Member desk" only
Show answerHide answer

Save this lesson to see this answer.

Question 7 of 10

A chart uses INPUT code, then loops back to that input while code is not "go". A translation has one INPUT before WHILE but none inside. What instruction is missing from the repeated body?
  1. code ← "go"
  2. INPUT code
  3. OUTPUT code
  4. CALL code
Show answerHide answer

Save this lesson to see this answer.

Question 8 of 10

A storage plan allows 2 through 8 boxes. Its condition is boxes >= 2 OR boxes <= 8. Tests with 2, 5, and 8 all pass. What pair of tests reveals the defect on both sides, and what complete condition repairs it?
  1. 1 and 9; boxes > 2 AND boxes < 8.
  2. 1 and 9; boxes >= 2 AND boxes <= 8.
  3. 2 and 8; boxes >= 2 AND boxes <= 8.
  4. 1 and 9; boxes <= 2 OR boxes >= 8.
Show answerHide answer

Save this lesson to see this answer.

Question 9 of 10

A machine accepts nonnegative even whole-number amounts and uses coins worth 10 and 2. Its plan gives at most one 10 and one 2 using IF. Input 12 is paid exactly. What test exposes incomplete payment, and what change pays every allowed amount with the fewest coins?
  1. 20; repeat only the 10-coin step.
  2. 14; repeat only the 2-coin step.
  3. 12; repeat both coin steps with WHILE.
  4. 20; repeat both coin steps with WHILE.
Show answerHide answer

Save this lesson to see this answer.

Question 10 of 10

A machine has unlimited coins worth 1, 5, and 7. Largest coin first pays 10 with 7, 1, 1, and 1. How many coins does a better payment use?
  1. 3
  2. 4
  3. 2
  4. 5
Show answerHide answer

Save this lesson to see this answer.

Stuck on your own question? Homework Help

Key Terms

70 Key Terms, each with its definition

A

Actual output
The actual output is the result an algorithm really produces when its instructions are followed with the test input.
A trace showing Silver at a Gold boundary records Silver as actual output, even though the test fails.
Algorithm
An algorithm is a finite, ordered set of precise steps that completes a task or solves a problem for its intended inputs.
An average-score algorithm reads three scores, adds them, divides by 3, and displays the result.
Arithmetic operator
An arithmetic operator specifies a calculation, such as adding, subtracting, multiplying, or dividing values.
The line area ← length * width uses the multiplication operator to calculate the stored area.
Assignment
An assignment evaluates a value or calculation and stores its result in the variable named on the left.
In total ← total + 4, the old total is read before the increased value replaces it.

B

Block
A block is a group of instructions belonging to the same structure, such as the body of a loop or an IF branch.
The true block of a ticket-price decision can set a price and then display a child-ticket message.
Boolean
A Boolean is a value with one of two possible states, true or false, often produced by a comparison.
The comparison score >= 50 produces true for 50 and false for 49 without changing the score.
Boundary data
Boundary data checks values at and just beside a limit, where an accepted range or the chosen action changes.
Testing 49 and 50 checks whether a pass threshold includes exactly 50 as the rule requires.

C

Call
A call is an instruction that runs a named procedure, then continues with the next instruction after it finishes.
After CALL playTune, the main algorithm waits for the tune routine to finish before its next output.
Case-sensitive comparison
A case-sensitive comparison treats uppercase and lowercase letters as different when comparing text values.
A check against "go" fails for "Go" unless the input is changed to matching case before testing.
Clarity
Clarity is how easy an algorithm is for a person to follow, inspect, and change through its wording and structure.
Descriptive names make the roles of total and count clearer than unexplained single letters.
Comparison operator
A comparison operator compares two values and produces true or false without changing either stored value.
The sign in age >= 16 includes age 16, while the sign in age > 16 excludes that boundary.
Condition
A condition is a test whose result is true or false and can choose a branch or control whether steps repeat.
The condition count <= 4 stays true at 4, allowing that final pass before the counter increases.
Condition-controlled loop
A condition-controlled loop repeats according to a true-or-false test, without needing a known repeat count.
A guessing game asks again while the guess differs from the secret, regardless of the number of attempts.
Connector
A connector is a small labeled circle marking where a flowchart route continues through another matching point.
Two circles labeled B let the reader continue one route in another column without a crossing line.
Conversion
A conversion between flowcharts and pseudocode changes an algorithm’s representation while preserving its behavior.
Converting a WHILE body to shapes keeps its final arrow returning to the same condition test.
Correctness
Correctness means an algorithm produces the required result for every valid input, including the edges of its supported range.
An even-number test must handle negative integers too when the accepted inputs include them.
Count-controlled loop
A count-controlled loop repeats a set number of times, using a counter to track progress through its passes.
A loop reading exactly six measurements can count from 1 through 6 before outputting their total.
Counterexample
A counterexample is a case that disproves a general claim by satisfying its premises but giving a result that contradicts it.
Coins 1, 3, and 4 disprove a universal largest-first minimum-coin claim: paying 6 takes fewer coins as 3 and 3.

D

Debugging
Debugging means locating errors in an algorithm and changing the faulty steps, then checking the repaired behavior.
Moving a total’s initialization outside its loop fixes the loss of earlier additions during each pass.
Decision symbol
A decision symbol is a diamond containing a condition with two exits, labeled for its true and false results.
At age < 12?, age 12 follows No because the less-than sign does not include equality.
Decomposition
Decomposition means breaking a large problem into smaller parts that can be planned, checked, and connected.
A checkout can be split into adding item prices, checking payment, and calculating the change.
DIV
DIV is an operator that gives the whole-number quotient, without the remainder or any fractional part.
23 DIV 5 gives 4, counting the complete groups; the leftover 3 is found using MOD.

E

Efficiency
Efficiency describes the amount of work an algorithm needs, often compared by counting operations or loop passes as inputs grow.
A formula with three arithmetic operations can need less work than a loop adding a thousand values.
ELSE branch
An ELSE branch runs when the associated IF condition is false, providing the second route through that decision.
When age < 12 is false, ELSE assigns the standard price before both routes reach the output.
ELSE IF chain
An ELSE IF chain checks alternatives from top to bottom and runs only the block of the first true condition.
A high score receives Gold and skips the lower award checks even though it also exceeds their limits.
Expected output
The expected output is the correct result required by the problem’s rules for a chosen input, calculated before the test.
If a valid score at the top boundary must receive Gold, write that expectation before tracing the decisions.

F

Flow line
A flow line is an arrow joining flowchart steps, showing which instruction or condition is reached next.
A backward flow line returns from the counter update to the diamond that controls the loop.
Flowchart
A flowchart is a diagram that describes an algorithm using shapes for different steps and arrows for their order.
A lamp-control flowchart branches at a light-level decision and joins its paths after the chosen action.
FOR loop
A FOR loop manages a counter through a stated range, repeating its body for the counter values in that range.
FOR i ← 2 TO 5 runs four times by default and changes the counter automatically at NEXT.

G

Generality
Generality describes the range of inputs or situations for which an algorithm works, beyond a single example.
A coin method that works for one coin set needs checking again when the available coin values change.

H

Hand tracing
Hand tracing, also called a dry run or desk check, follows an algorithm on paper using each current value in order.
A hand trace follows the false branch when a condition fails instead of executing both branches.

I

IF statement
An IF statement tests a condition and runs its true block when the condition succeeds, skipping it otherwise.
An IF without ELSE can display "Low battery" only when the stored battery level is below its limit.
Indentation
Indentation is spacing that moves lines to the right to show which instructions belong inside a block.
Lines inside WHILE are indented together, while the output after ENDWHILE returns to the outer level.
Infinite loop
An infinite loop repeats forever because execution never reaches a condition or route that ends its repetition.
A count that stays at 1 will never fail the test count <= 5, so that counting loop cannot finish.
Input
An input is data an algorithm receives, such as a number typed by a user or a value measured by a sensor.
A greenhouse algorithm receives the sensor’s temperature reading before deciding to open a vent.
Input validation
Input validation checks whether data meets the allowed type and range before the algorithm uses it for later work.
A coin-giving plan rejects amounts that cannot be paid exactly before reaching its coin loops.
Input/output symbol
An input/output symbol is a parallelogram representing data received by an algorithm or a result it displays.
The same parallelogram shape holds INPUT age or OUTPUT price; the words distinguish their jobs.
Integer
An integer is a whole-number value that can be negative, zero, or positive and has no fractional part.
A counter can hold integers such as 0, 1, and 2 as it tracks how many entries have been read.
Invalid data
Invalid data, also called erroneous data, is input outside the allowed type or range that the algorithm should handle or reject.
A score of -3 is invalid when the accepted range begins at 0, so the plan should reject it.
IPO chart
An IPO chart is a three-column plan separating the data received, the processing needed, and the required results.
For an area calculator, length and width are inputs, multiplication is processing, and area is output.
Iteration
Iteration is the control structure that repeats a group of instructions, usually under a count or condition.
A return arrow in a password chart asks for another entry after an incorrect attempt.

K

Keyword
A keyword is a word with a specific instruction or structural role in the chosen pseudocode style.
The keyword ELSE introduces the block followed when the preceding IF condition is false.

L

Logic error
A logic error is a fault in an algorithm’s steps that causes wrong behavior even though the steps can be followed.
A countdown using count > 1 has a logic error if its required final output is 1.
Logical operator
A logical operator combines or reverses true-or-false conditions; AND, OR, and NOT are the main examples.
AND joins the lower and upper age limits when a club accepts only ages within a particular range.
Loop counter
A loop counter is a variable that tracks passes or positions in a repeated sequence, changing as the loop advances.
The counter i can track five inputs while a separate variable counts only inputs that meet a condition.

M

MOD
MOD is an operator that gives the remainder of whole-number division, after complete groups have been counted.
23 MOD 5 gives 3 because four complete groups of 5 leave 3 out of the original 23.

N

Nested decision
A nested decision is a decision inside one branch of another, reached only when execution enters that branch.
A rainy-day branch can contain a second question about getting a ride; the dry-day branch skips it.
Normal data
Normal data consists of typical allowed input values used to check the algorithm’s behavior within its accepted range.
For scores allowed from 0 through 100, a score of 63 is normal data away from the endpoints.

O

Off-by-one error
An off-by-one error makes a loop execute once too many or too few, often because an endpoint is handled wrongly.
Starting at 1 with count < 5 gives four passes when the intended range is 1 through 5.
Output
An output is a result an algorithm produces, such as a displayed number, printed message, or control signal.
A ticket machine displays the calculated price after its decision selects the correct age band.

P

Predefined-process symbol
A predefined-process symbol is a rectangle with extra vertical side lines that calls a routine defined elsewhere.
A box labeled drawSquare runs the square-drawing steps before the main chart continues.
Procedure
A procedure, or sub-routine, is a named group of instructions defined once and executed whenever it is called.
A drawSquare procedure for a robot keeps four movements and turns together for repeated calls.
Procedure definition
A procedure definition gives a routine its name and body, making the instructions available for later calls.
Writing PROCEDURE beep with its body defines the routine, but no beep occurs until it is called.
Process symbol
A process symbol is a rectangle representing an action or calculation that occurs at that point in a flowchart.
A rectangle containing count ← count + 1 changes the counter before the next decision test.
Processing
Processing is the work an algorithm does with data, including calculations, decisions, and other actions.
Adding three scores and dividing their sum by 3 is processing in an average-score algorithm.
Program
A program expresses an algorithm in a programming language so a computer can execute its instructions.
A Scratch program can carry out the same decisions that were first planned in a flowchart.
Pseudocode
Pseudocode describes an algorithm in short, structured, English-like instructions without using one programming language.
A plan can use INPUT age before its language-specific input and conversion code is written.

R

REPEAT ... UNTIL loop
A REPEAT ... UNTIL loop tests after its body and stops on true, so the body always runs at least once.
A REPEAT loop asks for a score, then checks whether that score lies within the allowed range.
Running total
A running total stores the sum accumulated so far by adding each new value to the value already stored.
Inputs 4, 6, and 3 make a running total change from 0 to 4, then 10, then 13.

S

Selection
Selection is the control structure that chooses which instructions run by testing a true-or-false condition.
A ticket plan selects one price for a child and a different price for someone above the child band.
Sequence
Sequence is the control structure in which instructions run one after another in their specified order.
An algorithm reads the dimensions before calculating an area, then displays the calculated value.
Step
A step is the amount by which a FOR counter changes between passes; the default increase in this style is 1.
With STEP -1, a loop counts down from 6 through 2 instead of increasing its counter.
String
A string is a text value made from characters, which may include letters, digits, spaces, or punctuation.
"17" is a string of two digits, while 17 is a number that can take part in arithmetic.

T

Temporary variable
A temporary variable holds a value needed later, often preserving it before another assignment replaces the original.
Saving the original a in temp lets a swap recover it after a has received the value of b.
Terminator
A terminator is an oval or rounded rectangle that marks the beginning or end of an algorithm in a flowchart.
A main flowchart begins at a Start terminator and finishes at Stop, which has no outgoing flow line.
Test case
A test case specifies a particular input and the result required by the rules, so the algorithm can be checked against it.
The zero-amount test case for a change machine expects no coins and no unpaid remainder.
Test plan
A test plan lists inputs and expected results, then records actual results and whether each comparison passes or fails.
A test row can record age 12, the expected standard price, the actual price, and a pass or fail.
Trace table
A trace table records variable values and outputs during a trace, showing changes and keeping the earlier history.
A total column may show 0, 2, and 7 before the output column records the final displayed 7.

V

Variable
A variable is a named place that stores a value the algorithm can read or replace as its instructions run.
The variable remainingSeats decreases when the booking algorithm accepts another reservation.

W

WHILE loop
A WHILE loop tests before each pass and repeats its body while the condition is true, allowing zero passes.
A value already above a WHILE loop’s upper limit skips its body and continues after ENDWHILE.

About this lesson

By StudeliReport a mistake

Make your own Study Materials

Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.

Get Started