READFIELD — Forward. Forward. Turn left. Jump. Turn on light. Repeat.

On Ryan Worster’s iPad screen, an animated robot followed the commands he entered, traveling around a grid to light up certain squares.

After a little time using the Light Bot app, Worster, a Maranacook Community Middle School seventh grader from Mount Vernon, had passed the stage of trial and error and was beginning to think in entire strings of commands, plotting out loud before entering them on the screen. Worster had completed all the levels already and was running through them a second time to see if he could program more efficiently, using fewer commands to direct the robot’s movements.

“I think it’s cool to make something completely independent to do what you want to do,” Worster said. “What computer science is, is trying to create something to do what you want.”

Worster was one of a few dozen students at Maranacook and more than 14 million nationwide who tried their hand at computer programming this week as part of the Hour of Code, an initiative to promote computer science education in public schools. According to Project Login, more than 40 Maine schools participated in the Hour of Code this week.

Maranacook technology integration teacher Diane MacGregor invited any middle school student who wanted to bring their iPad to two classrooms on Thursday and Friday during tutorial, a period when students have some choice of what to do.

Those who chose to take part watched videos created by the nonprofit organization Code.org to promote the Hour of Code, featuring entertainers and athletes such as basketball player Chris Bosh as well as tech moguls like Microsoft founder Bill Gates and Facebook creator Mark Zuckerberg.

MacGregor talked with the students briefly about why it’s important to study programming.

“There’s a lot of jobs that make good money in computer programming, but they’re not getting filled because no one knows how to do it,” said Laura Ireland, a seventh grader from Wayne.

Ireland said she’d like to work in technology and hopes to design her own app someday. She said she’s attracted to the field both by the money to be made and the pride she could have in creating something people use and enjoy.

MacGregor said she’d been concerned that the students’ iPads, which the school chose through the Maine Learning Technology Initiative, weren’t up to the task of coding, but then she found Light Bot and Hopscotch, introductory programming apps suited to the iPads’ touchscreens.

In the apps, the students didn’t learn a typed programming language. Instead, they were presented with a menu of commands that they could drag and drop into sequences.

MacGregor said she thought that was enough for a brief activity, to make sure the students were engaged and teach them the basic principles and logic of writing a computer program.

“I think their gateway is this icon-driven approach that still takes you line by line by line through the things that you want to happen, and it teaches you order,” MacGregor said. “From there they can go into more sophisticated coding.”

Ireland demonstrated how Hopscotch could be used to create games or animations by choosing a character — she tapped the cupcake with a face — then telling it how to move around the screen.

She dragged a bar labeled “leave a trail” into the work pane so that the cupcake would draw a line behind it. Then she added another bar that said “move distance” and typed in 600 so that the cupcake would move to the right 600 units. Other commands can change the color or width of a line, rotate a character a specified number of degrees, return it to its starting spot or tell it to respond to a tilting of the iPad or a loud noise like a clap.

Combining these commands, the students made the characters “dance” or draw faces. Some created games where the challenge is to move a character across the screen without hitting any obstacles.

Struggling to get one of the characters to draw a circle, Worster created something entirely different and perhaps even more interesting. He made it draw a short line, then reverse direction at an angle, then repeat that thousands of times until it created a design and eventually filled in a circle. By altering the angle, he found he could create different designs like the ones kids used to produce with pen and paper in Spirograph kits.

The need for trial and error, and the prospect that a tiny error can mess up an entire program, makes computer programming hard but also fun, said Jacek Twarog, a sixth grader from Fayette.

“It’s like a game, one of those puzzle games,” he said. “It’s the kind of game where you have to think and know what to do.”

MacGregor was thrilled with the enthusiasm she saw from the students.

The challenge will be helping them do something with that enthusiasm. Like most high schools, Manaracook does not teach computer programming.

At the very least, MacGregor said, they can offer students the time and space to work on coding during tutorial periods and try to come up with more opportunities from there.

Susan McMillan — 621-5645[email protected]Twitter: @s_e_mcmillan