Imperative programming

Traditionally, we write code that describes how it should solve a problem. Each line of code is sequentially executed to produce a desired outcome, which is known as imperative programming. The imperative paradigm forces programmers to write "how" a program will solve a certain task. Note that in the previous statement, the keyword is "how."

Here's an example:

let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]var numbersLessThanFive = [Int]()for index in 0..<numbers.count     {    if numbers[index] > 5         {        numbersLessThanFive.append(numbers[index])        }    }

As you can see, we sequentially execute a series of instructions to produce a desired output.

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.