Comments with // (7a)

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Comments with // (7a)

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line is a correct Cambridge pseudocode comment?
A // Add the two marks together
B Add the two marks together //
2. What does the computer do with the text after // on a line?
A It ignores it
B It runs it as code
3. Which is the correct way to put a short comment at the end of a line?
A Total ← Total + Mark add mark //
B Total ← Total + Mark // add mark
4. A comment is placed on its own line above this code. Which is correct?
A // Ask for the user's age INPUT Age
B Ask for the user's age INPUT Age
5. A comment needs two lines. Which is correct?
A // Check the password before logging in
B // Check the password // before logging in

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1// Calculate the average mark AA short comment at the end of a line, explaining only that line of code
2Total ← Total + Mark // add to total B// Check if the password is long enough // Passwords must have 8 or more characters
3A comment that explains the purpose of the code is written on its own line above it CThe comment starts with only one slash. A comment needs two forward slashes //, so the first line is not a valid comment.
4A multi-line comment needs // at the start of every line D// Ask the user for their age INPUT Age
5/ Total of all the marks Total ← 0 EOnly the first two lines are comments, but a long comment that runs over several lines needs // on every line. A comment line without // would be treated as code.
6// Read the number // of students INPUT Students OUTPUT Students FA comment on its own line above the code, explaining what the next lines do

Definitions

//

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
__ Ask the user for their age INPUT Age
2.
Total ← 0 __ Start the total at zero
3.
// Calculate the area of the rectangle __ Width and Length must be positive Area ← Width * Length
4.
FOR Count ← 1 TO 5 __ Repeat five times OUTPUT Count NEXT Count
5.
__ Check if the student has passed IF Mark >= 50 THEN OUTPUT "Pass"

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A DECLARE Width : INTEGER
B DECLARE Area : INTEGER
C INPUT Width
D Area ← Width * Width # square
E OUTPUT Area
Question 2
A // Total of two marks
B Total ← Mark1 + Mark2 / add them
C OUTPUT Total
Question 3
A // This program checks age
B and prints a message
C INPUT Age
D IF Age >= 18 THEN
E OUTPUT "Adult"
F ENDIF
Question 4
A -- Ask for the user's name
B INPUT Name
C OUTPUT "Hello ", Name
Question 5
A DECLARE Count : INTEGER
B Count ← 0
C // add one Count ← Count + 1
D OUTPUT Count

Answer Key

Comments with // (7a)
Section A: Quick Questions
Q1
A — // Add the two marks together
Q2
A — It ignores it
Q3
B — Total ← Total + Mark // add mark
Q4
A — // Ask for the user's age INPUT Age
Q5
B — // Check the password // before logging in
Section B: Match the Pairs
Q1
// Calculate the average mark → A comment on its own line above the code, explaining what the next lines do
Q2
Total ← Total + Mark // add to total → A short comment at the end of a line, explaining only that line of code
Q3
A comment that explains the purpose of the code is written on its own line above it → // Ask the user for their age INPUT Age
Q4
A multi-line comment needs // at the start of every line → // Check if the password is long enough // Passwords must have 8 or more characters
Q5
/ Total of all the marks Total ← 0 → The comment starts with only one slash. A comment needs two forward slashes //, so the first line is not a valid comment.
Q6
// Read the number // of students INPUT Students OUTPUT Students → Only the first two lines are comments, but a long comment that runs over several lines needs // on every line. A comment line without // would be treated as code.
Section C: Definitions
Q1
// — Two forward slashes start a comment. Everything after // to the end of the line is ignored by the computer and only explains the code to the reader.
Section D: Fill in the Blanks
Q1
// Ask the user for their age INPUT Age
Q2
Total ← 0 // Start the total at zero
Q3
// Calculate the area of the rectangle // Width and Length must be positive Area ← Width * Length
Q4
FOR Count ← 1 TO 5 // Repeat five times OUTPUT Count NEXT Count
Q5
// Check if the student has passed IF Mark >= 50 THEN OUTPUT "Pass"
Section E: Spot the Error
Q1
D — Cambridge pseudocode comments start with //, not #. The line should be: Area ← Width * Width // square
Q2
B — A comment needs two forward slashes. A single / is the division operator, so the line should end with // add them.
Q3
B — Each line of a multi-line comment must start with //. Line 2 should be: // and prints a message
Q4
A — -- is not the comment marker in Cambridge pseudocode. A comment above the code must start with //: // Ask for the user's name
Q5
C — Everything after // is ignored, so the code here would be ignored too. The code must come first and the comment after it: Count ← Count + 1 // add one