CS: Loops and Conditional Statements
Using repetition and decisions in programs
Using repetition and decisions in programs
CS - Grade 6-8
- 1
Trace this code and write the output: count = 1; while count <= 4: print(count); count = count + 1.
- 2
A program should print Even if a number is divisible by 2 and Odd if it is not. Write an if-else statement in pseudocode for this task.
- 3
Trace this for loop and write the final value of total: total = 0; for i from 1 to 5: total = total + i.
- 4
Explain the difference between a loop and a conditional statement.
- 5
Find the bug in this code and explain how to fix it: x = 1; while x < 10: print(x).
- 6
Write a loop in pseudocode that prints the numbers 10, 9, 8, 7, and 6.
- 7
Trace this code and write the output: score = 82; if score >= 90: print(A); else if score >= 80: print(B); else: print(C).
- 8
A game gives 10 points for each coin collected. Write pseudocode that uses a loop to add points for 6 coins.
- 9
Trace this nested decision and write what is printed: age = 13; hasTicket = true; if age >= 12: if hasTicket == true: print(Enter); else: print(Buy ticket); else: print(Too young).
- 10
Choose whether a for loop or while loop is better for this task and explain why: keep asking for a password until the user enters the correct password.
- 11
Write an if-else statement in pseudocode that prints Freezing if temperature is 32 or below, and Not freezing otherwise.
- 12
Trace this code and write the final value of x: x = 3; for i from 1 to 4: if i % 2 == 0: x = x + i.
Related Cheat Sheets
More CS Worksheets
CS: Algorithms and Flowcharts
Grade 6-8 · 12 problems
CS: Arrays and Lists
Grade 9-12 · 12 problems
CS: Big-O Notation and Algorithm Efficiency
Grade 9-12 · 12 problems
CS: Binary Numbers and Number Systems
Grade 6-8 · 12 problems
More Grade 6-8 Worksheets
Ratios & Proportions
Math · 8 problems
Forces & Motion
Physics · 8 problems
Figurative Language
Language Arts · 8 problems
US Government & Civics
Social Studies · 8 problems