Imperative Programming Constructs Flashcards
7 cards from real Picat practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Imperative Programming Constructs flashcards as text
Which operator is used for destructive assignment in Picat's imperative mode?
Answer: :=
In Picat's imperative mode, := performs destructive (mutable) assignment, unlike = which is unification.
What does the `foreach` loop in Picat use to iterate over a list?
Answer: foreach(X in List) do ... end
Picat's foreach loop uses the syntax `foreach(X in List) do ... end` to iterate over elements.
In Picat, what happens when a `while` loop condition becomes false?
Answer: The loop terminates and execution continues after `end`
When the while loop condition is false, the loop exits and control passes to the statement after the end keyword.
How do you declare a local variable inside a Picat imperative function?
Answer: No declaration needed; first assignment creates it
In Picat, variables do not need explicit declarations; the first assignment in a scope implicitly introduces them.
Which Picat construct provides a `do ... while` style loop that tests the condition at the end?
Answer: Picat has no post-condition loop construct
Picat does not have a built-in do-while construct; programmers simulate post-condition loops with while or recursion.
In Picat, what is the result of executing `X := 5, X := X + 1`?
Answer: X becomes 6
The := operator allows reassignment, so X is first set to 5 and then updated to 6.
What is the correct way to break out of a `foreach` loop early in Picat?
Answer: Use a boolean flag variable with a while loop instead
Picat's foreach does not support break; the idiomatic workaround is to use a while loop with a flag or a recursive helper.