Posted by : Rhyf Ahmad Wednesday, May 13, 2015

In Objective-C, you can repeatedly execute a sequence of code in several ways.These looping capabilities are the subject of this chapter, and they consist of the following: 
  • The for statement 
  • The while statement 
  • The do statement

We start with a simple example: counting numbers. If you were to arrange 15 marbles into the shape of a triangle, you would end up with an arrangement that might look something like Figure 5.1.


The first row of the triangle contains one marble, the second row contains two marbles, and so on. In general, the number of marbles required to form a triangle containing n rows would be the sum of the integers from 1 through n.This sum is known as a triangular number. If you started at 1, the fourth triangular number would be the sum of the consecutive integers 1–4 (1 + 2 + 3 + 4), or 10. Suppose you wanted to write a program that calculated and displayed the value of the eighth triangular number. Obviously, you could easily calculate this number in your head, but for the sake of argument, let’s assume you wanted to write a program in Objective-C to perform this task. Program 5.1 illustrates such a program.

Contents:

The for Statement
  1. Keyboard Input
  2. Nested for Loops
  3. for Loop Variants

The while Statement
The do Statement
The break Statement
The continue Statement
Summary
Exercises



Ebook Preview
Get the ebook now (234 kB)

If the link above doesn't work, try the link below

Leave a Reply

You can leave a comment to request any article(s), software(s), ebook(s) or report the dead link.
Then I will reply as soon as I can :)

Subscribe to Posts | Subscribe to Comments

Welcome to My Blog

Recent Post

Recent Posts Widget
Instagram

- Copyright © Madriva -Robotic Notes- Powered by Blogger - Designed by Johanes Djogan -