What is the main purpose of writing pseudocode before coding?
Think about how pseudocode helps programmers think through problems.
Pseudocode is used to plan the logic of a program in plain language. It helps programmers organize their thoughts before writing actual code.
Given the following pseudocode, what will be the final value of total?
SET total TO 0 FOR each number FROM 1 TO 4 ADD number TO total END FOR
Sum the numbers 1 + 2 + 3 + 4 step by step.
The loop adds 1 + 2 + 3 + 4 to total, which equals 10.
Which statement best describes the difference between pseudocode and a flowchart?
Think about how each method represents the steps of a program.
Pseudocode is text-based and describes steps in words. Flowcharts use shapes and arrows to visually represent the flow of steps.
Which option shows pseudocode with a logical error?
Option A: SET count TO 5 WHILE count > 0 PRINT count DECREMENT count BY 1 END WHILE Option B: SET count TO 0 WHILE count < 5 PRINT count END WHILE Option C: SET total TO 0 FOR i FROM 1 TO 3 ADD i TO total END FOR Option D: SET x TO 10 IF x > 5 THEN PRINT "High" END IF
Look for loops that might never end.
Option D's loop never changes count, so it runs forever, causing an infinite loop.
You want to write pseudocode to plan a program that checks if a number is prime. Which pseudocode snippet correctly plans this task?
Think about how to test divisibility to confirm if a number is prime.
Option B correctly checks divisibility from 2 up to number-1 and stops if a divisor is found, printing "Not prime"; otherwise, it prints "Prime".