Imperative programming expresses computation as a sequence of instructions that describe how to perform a task. An average-age calculation can add each age to a running total, then divide that total by the list size. This contrasts with declarative programming, which states the desired result—such as the average—without specifying each operation. section 7.6.3
val ages = listOf(20,40,50,15,80);
var totalAges = 0
for (age in ages) {
totalAges = totalAges + age
}
val averageAge = totalAges / ages.size
A loop, mutable total, and final division make the calculation procedure explicit. section 7.6.3
The same pattern appears in imperative-style Gherkin: scenarios list low-level interactions such as entering fields, setting options, and clicking buttons. Such detail can obscure business intent, couple scenarios to the interface, and increase maintenance; declarative scenarios instead describe the requested outcome. section 7.6.3
Finding a hotel
An imperative scenario says to enter Paris, choose dates and distance, and press search. A more declarative version asks for a hotel within 10 km of Paris for two nights on the specified date. section 7.6.3













