Long-Term Learning

Learn efficiently and remember over time.

Start Long-Term Learning

Get personalized study reminders at intervals optimized for better retention.
Track your progress on this set by creating a folder
Or add to an existing folder

Add this set to a folder

  • Three kinds of loops in Objective-C

    For, while, do

    for (general)

    for (initial expression; loop condition; loop expression)
    program statement

    for (example)

    int n, triangularNumber;

    triangularNumber = 0;

    for ( n = 1; n <=200; n = n + 1)
    triangularNumber += n;

    The 200th triangular number

    initial expression

    sets the initial values before the loop begins

    loop condition

    specifies the condition or conditions necessary for the loop to continue

    Relational operators


    For loop summary

    1. The intial expression is evaluated first. This expression usually sets a variable that is used inside the loop, generally referred to as the index variable, to some intial value (generally 0 or 1)

    2. The looping condition is evaluated. If the condition is not satisfied (the expression is false), the loop immediately terminates. Execution continues with the program statement that immediately follows the loop.

    3. The program statement that constitutes the body of the loop is executed.

    4. The looping expression is evaluated.

    5. Return to Step 2

    block of code

    for (initial expression; loop condition; loop expression)
    program statement
    program statement
    program statement

    the increment operator


    example: ++n or n++

    the decrement operator


    example --n or n--

    width specification

    %i = 1 column
    %2i = 2 columns
    %3i = 3 columns


    Enables the programmer to type values into the program

    Use commas to seperate variables in your for loop statement

    for ( i = 0, j= 10........

    while (general)

    while (expression)
    program statement

    Loops until the expression is false

    while loop example

    int count = 1;

    while ( count <= 5 )
    NSLog(@"%i", count);

    for loop vs. while loop comparison

    initial expression
    while (loop condition)
    program statement
    loop expression

    do (general)

    program statement
    while (expression)

    Tests the loop at the end rather than at the beginning so it runs at least once

    The break statement

    Leaves a loop as soon as a condition occurs


    The continue statement

    Any statement that appears after the continue statement is skipped.

    Please allow access to your computer’s microphone to use Voice Recording.

    Having trouble? Click here for help.

    We can’t access your microphone!

    Click the icon above to update your browser permissions above and try again


    Reload the page to try again!


    Press Cmd-0 to reset your zoom

    Press Ctrl-0 to reset your zoom

    It looks like your browser might be zoomed in or out. Your browser needs to be zoomed to a normal size to record audio.

    Please upgrade Flash or install Chrome
    to use Voice Recording.

    For more help, see our troubleshooting page.

    Your microphone is muted

    For help fixing this issue, see this FAQ.

    Star this term

    You can study starred terms together

    NEW! Voice Recording

    This is a Plus feature