The 3 types of loops

Hello!

What is the difference between the 3 types of loops?

yes, I've searched everywhere but still cannot understand it!

Comments

  • : Hello!
    :
    : What is the difference between the 3 types of loops?
    :
    : yes, I've searched everywhere but still cannot understand it!
    :
    :
    Here are three basic kinds of loops. From this you should be able to answer the question.

    for loop
    [code]
    for(int i = 0; i < n; i++)
    {

    }
    [/code]

    do loop
    [code]
    int i = 0;
    do {
    //
    i++;
    } while(i < n);
    [/code]

    while loop
    [code]
    int i = 0;
    while(i < n)
    {
    i++;
    }
    [/code]

  • : Hello!
    :
    : What is the difference between the 3 types of loops?
    :
    : yes, I've searched everywhere but still cannot understand it!
    :
    :
    for loop: normally used when a certain number of iterations is known in advance.

    do..while loop: test to exit the loop is done at the end of the block, so the loop block is always executed at least once.

    while loop: test for the loop is done at the start of the block, so the loop body may or may not ever be executed.

    there are other details, and each can be setup to mimic the other types, but there is a simple definition for you.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories