Search⌘ K

Sorting Children's Names

Explore how to create a Ruby program that accepts multiple children's names, stores them dynamically in an array, and sorts them alphabetically. Understand how to control program flow with loops, manage array methods like adding elements and sorting, and format output effectively. This lesson helps build foundational skills in handling composite data types and performing common operations on arrays.

Problem

Write a program that asks for a list of names, and then outputs them in alphabetical order. The program should end when the user enters 0.

%0 node_1649238699244 Dominic node_1 Courtney node_2 Anna node_3 Angela node_1649238724075 Ella node_1664873921050 Toby node_1664873949220 Emma
Array
Enter child names in class: (0 to finish):
Dominic
Courtney
Anna
Angela
Ella
Toby
Emma
0
Children names in order:
Angela, Anna, Courtney, Dominic, Ella, Emma, Toby
Sorting children's names

Purpose

...