Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

2. It’s All Just Code: Under the hood > Loops perform an action over and over

Loops perform an action over and over

Here’s a peculiar thing about most large programs: they almost always involve doing certain things over and over again. And that’s what loops are for—they tell your program to keep executing a certain set of statements as long as some condition is true (or false!).

Note

That’s a big part of why booleans are so important. A loop uses a test to figure out if it should keep looping.

image with no caption

IDE Tip: Brackets

If your brackets (or braces—either name will do) don’t match up, your program won’t build, which leads to frustrating bugs. Luckily, the IDE can help with this! Put your cursor on a bracket, and the IDE highlights its match:

image with no caption

Use a code snippet to write simple for loops

You’ll be typing for loops in just a minute, and the IDE can help speed up your coding a little. Type for followed by two tabs, and the IDE will automatically insert code for you. If you type a new variable, it’ll automatically update the rest of the snippet. Press tab again, and the cursor will jump to the length.


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial