You are previewing Corona SDK Application Design.

Corona SDK Application Design

Cover of Corona SDK Application Design by Daniel Williams Published by Packt Publishing

Loops, loops, and loops

Take a moment and think back to the last game you played. Was it Pong? A racing game? Or was it a puzzle game? No matter what the genre was, all of these games had one thing in common: they all used loops.

In almost every app that you make from here on, your app is going to have a repetitive action. These actions can be anything from keeping track of the time remaining in a game to creating onscreen items. With loops, you can avoid copying and pasting dozens of lines of code and save yourself a lot of time.

The for loop

The first loop that we are going to cover is the for loop. For loops are great for a predefined number of repetitions. If you know that you need to make a player take three steps in a direction, a for loop ...

The best content for your career. Discover unlimited learning on demand for around $1/day.