How often Loops: for, while and do-while is asked
7 of 8
papers asked it
avg 14 marks · last Supp 2025
Worth 1–10 marks when it appears as a written question, plus 2 multiple-choice items.
Where it was asked
The questions
May/Jun 2018, Q1.72 marks · multiple choice
What will be displayed on the screen by the following code? int start = 0; int count = 10; while (start < count) { cout << start << " , "; count++; }
May/Jun 2018, Q57 marks
Ella and Bella are two friends who share a stall and a single cash register at a fair. To keep track of each one's sales, whoever makes a sale enters either the character 'E' (for Ella) or 'B' (for Bella) to indicate whose product was sold, followed by the value of that sale. An incomplete C++ program is given below that is meant to determine the running totals of Ella's and Bella's sales. The program declares a char variable name (to hold 'E' or 'B'), a float variable sale (the value of one specific sale), and two float variables eSales and bSales (both initialised to 0) to hold the totals for Ella and Bella respectively. It prompts 'Whose product? Enter 'E' (Ella) or 'B' (Bella)' and reads the first character into name. After a comment marking the place for '//your statements', the program sets output formatting with cout.setf(ios::fixed) and cout.precision(2), then displays 'Ella sold goods to the value of R' followed by eSales, and 'Bella sold goods to the value of R' followed by bSales, before returning 0. You must complete the program by writing the while loop structure (to replace the '//your statements' comment) that repeatedly inputs a sale amount and adds it to the correct person's running total depending on whether 'E' or 'B' was entered, and that also reads the next character indicating whose sale is next. The loop must stop as soon as any character other than 'E' or 'B' is entered.
May/Jun 2016, Q6.12 marks
Write a for-statement that displays the numbers 1 through 10 on the screen.
May/Jun 2016, Q6.23 marks
Write a while-statement that displays the numbers 1 through 10 on the screen.
May/Jun 2016, Q6.32 marks
The following code is intended to display the numbers 1, 2, 3 and 4 on the screen, but it is not working correctly. Correct the errors in the code: line 1 reads 'int num = 1,'; line 2 reads 'while (num < 4)'; line 3 reads 'cout << num << endl,'; line 4 reads '// endwhile'.
The full Spot Map and the marks by year.