Search a list of records: Difference between revisions

Content added Content deleted
m (Formatting.)
Line 1,888: Line 1,888:
echo "Index of the first city whose name is “Dar Es Salaam”: ",
echo "Index of the first city whose name is “Dar Es Salaam”: ",
Cities.findIt(it.name == "Dar Es Salaam")
Cities.findIt(it.name == "Dar Es Salaam")

let idx1 = Cities.findIt(it.population < 5)
let idx1 = Cities.findIt(it.population < 5)
echo "Name of the first city whose population is less than 5 million: ",
echo "Name of the first city whose population is less than 5 million: ",
if idx1 == -1: "<none>" else: Cities[idx1].name
if idx1 == -1: "<none>" else: Cities[idx1].name

let idx2 = Cities.findIt(it.name.startsWith("A"))
let idx2 = Cities.findIt(it.name.startsWith("A"))
echo "Population of the first city whose name starts with the letter “A”: ",
echo "Population of the first city whose name starts with the letter “A”: ",