Example#17(Array.Iter)

Posted by Rey Dacoco in

Problem: Make a console application that will convert the following singular nouns to plural. Use Array.Iter:

1. ally
2. army
3. baby
4. lady
5. navy

// Learn more about F# at http://fsharp.net
open System
//change the console title
System.Console.Title<-"Convert to Plural"
//adds the foreground and background color
System.Console.ForegroundColor<-ConsoleColor.Blue
System.Console.BackgroundColor<-ConsoleColor.White
//clears the screen. This is to apply the background color once the
//console application is loaded
System.Console.Clear()
//assigns the singular nouns to our array variable singularnouns
let singularnouns=[|"ally";"army";"baby";"lady";"navy"|]
printfn "Singular words:"
//iterates through the values of our singularnouns array variable
singularnouns|>Array.iter(fun singularwords->printfn "%s" singularwords)
printfn "Plural words:"
//iterates through the values of our singularnouns array variable
//replace the word in each array element from "y" to "ies"
singularnouns|>Array.iter(fun pluralnouns->
let pluralwords= pluralnouns.Replace("y","ies")
printfn "%s" pluralwords)

This will display the following output:

Contributor

My photo
I am just a simple man with a simple mind. And this is my simple blog. New Posts will be available soon. Enjoy reading and never stop learning:)

Total Pageviews

Link List

Archives

Got questions? You can reach me here: