Howdy, Stranger!

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

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

examples 4 loop in turbo c

shahdshahd Posts: 1Member
hi every one :)

i'de like to ask any one who can help me to find the way to make a loop pragramme by using turbo c ..
and i need also at least one example 4 that so i can understand better;)
thanx every body 4 ur supporting

shahd

Comments

  • DonotaloDonotalo Posts: 715Member
    There are three main kind of loop: the [red]for[/red] loop, [green]while[/green] loop and [blue]do while[/blue] loop. each one is discussed briefly here.

    [red]for[/red] loop:
    [code][italic]
    for (initialization; boolean checking; increament or decreament) {
    //Loop body
    }[/italic]
    [/code]
    all of the parts [italic]initialization, boolean checking and increament or decreament[/italic] are optional here. If u want to initialize something, put the code into initialization portion. boolean checking is an expression that returns true or false. when it is false, the loop breaks. until then it continues. in [red]for[/red] loop, the initialization portion will execute first. then it evaluates boolean checking part. if it returns true, the program goes through the body (block). after executing the last statement, it will evaluate increament or decreament portion. then it checks again the boolean checking part. if it returns true the whole process will continue again. here is an example of showing all of the array elements using [red]for[/red] loop:
    [code]
    for (i = 0; i < array_size; ++i) {
    printf("%d ", array[i]);
    }
    [/code]

    [green]while[/green] loop:
    [code][italic]
    while (boolean checking) {
    //Loop body
    }[/italic]
    [/code]
    the boolean checking portion works exactly the same way as that of the [red]for[/red] loop. however, u can't keep it empty. the boolean checking is not optional here. in while loop, the boolean checking part executes first. if it returns true, then the loop body executes. after executing the last statement, the program checks the boolean xpression again and if it returns true, the whole process will continue. here is the same example shown above using [green]while[/green] loop:
    [code]
    i = 0;
    while (i < array_size) {
    printf("%d ", array[i]);
    ++i;
    }
    [/code]

    [blue]do while[/blue] loop:
    [code][italic]
    do {
    //Loop body
    }
    while(boolean checking);[/italic]
    [/code]
    the [blue]do while[/blue] loop has an exception: it executes the loop body first and then checks the boolean checking. so, unlike [red]for[/red] and [green]while[/green] loop, [blue]do while[/blue] loop will execute the loop body at least once. here is the previously shown example using [blue]do while[/blue] loop:
    [code]
    i = 0;
    do {
    printf("%d ", array[i]);
    ++i;
    }
    while(i < array_size);
    [/code]
Sign In or Register to comment.