August 2018
Intermediate to advanced
380 pages
10h 2m
English
How imperative turns into declarative is best understood by means of an example. Most likely, you already know the go-to statement. You have heard that using the go-to statement is bad practice. Why? Consider an example of a loop. It is possible to express a loop using only the go-to statement:
#include <iostream>using namespace std;int main() { int x = 0; loop_start: x++; cout << x << "\n"; if (x < 10) goto loop_start; return 0;}
From the preceding example, imagine you need to express a while loop. You have the variable x and you need to increment it in a loop by one until it reaches 10. In modern languages such as Java, you would be able to do this using the while loop, but it is also possible to do that using ...