Solution: displayMenu() Function

This lesson provides a solution to the coding challenge given in the previous lesson.

We'll cover the following...

Solution #

Here is how the printMenu() function can be written to output the whole menu.

Press + to interact
import std.stdio;
void printMenu(string[] items, int firstNumber) {
foreach (i, item; items) {
writeln(' ', i + firstNumber, ' ', item);
}
}
void main() {
string[] items = [ "Black", "Red", "Green", "Blue", "White" ];
printMenu(items, 1);
}
...