Recall & Review
beginner
What is a LOOP in PostgreSQL procedural language?
A LOOP is a control structure that repeats a block of code indefinitely until a
EXIT statement is encountered.Click to reveal answer
beginner
How does a WHILE loop work in PostgreSQL?
A WHILE loop repeats the code inside it as long as the given condition is true. It checks the condition before each iteration.
Click to reveal answer
intermediate
What is the difference between a FOR loop and a WHILE loop in PostgreSQL?
A FOR loop iterates over a range or query result automatically, while a WHILE loop repeats based on a condition you write and check manually.
Click to reveal answer
beginner
How do you exit a LOOP in PostgreSQL?
You use the
EXIT statement to stop the LOOP when a certain condition is met.Click to reveal answer
beginner
Write a simple example of a FOR loop in PostgreSQL that prints numbers from 1 to 5.
DECLARE i INT;
BEGIN
FOR i IN 1..5 LOOP
RAISE NOTICE 'Number: %', i;
END LOOP;
END;
Click to reveal answer
Which statement correctly exits a LOOP in PostgreSQL?
✗ Incorrect
In PostgreSQL, the EXIT statement is used to leave a LOOP.
What does a WHILE loop do before each iteration?
✗ Incorrect
A WHILE loop checks the condition before running the loop body each time.
Which loop type automatically iterates over a range in PostgreSQL?
✗ Incorrect
FOR loops in PostgreSQL can iterate automatically over a range or query results.
What keyword starts a loop block in PostgreSQL?
✗ Incorrect
The LOOP keyword starts a loop block in PostgreSQL.
How do you write a FOR loop to iterate from 1 to 10 in PostgreSQL?
✗ Incorrect
The correct syntax uses two dots: FOR i IN 1..10 LOOP
Explain how LOOP, WHILE, and FOR loops differ in PostgreSQL and when you might use each.
Think about how each loop controls repetition and what stops it.
You got /6 concepts.
Describe how to safely exit a LOOP in PostgreSQL and why it is important.
Consider what happens if you forget to exit a loop.
You got /4 concepts.