enfrptes

sendassignment@tutorspoint.com

Loop Statements Homework Help

Tutorspoint.com is an excellent site, which caters to all queries of programming students, regarding java assignments related to topics including Loop Statements homework help with quality solutions.

Since all the Java Assignment writing help is offered at reasonable rates, Tutorspoint expert service is highly recommended by students worldwide from many universities of U.S. America, Australia, Canada, Germany, Ireland, and Denmark

 

What are Loop Statements

The looping statements are used to execute a group of statements repeatedly until some condition is satisfied. The looping structures are

1) While Structure

2) Do...While Structure

3) For Structure

 

What is While Structure

This is a simple looping statement when executed, the computer first evaluates the test condition. The control is transferred to the next statement if the value is false.

The body of the loop is executed repeatedly until the test condition becomes false. The control is transferred to the next statement when the test condition becomes false.

while(test condition)

{

body of the loop;

}

next statement;

 

Example:

#include

main ()

{

int j;

j=1;

while (j<5)

{

printf(“welcome”);

j++;

}

}

 

What is Do...While Structure

When this statement has executed the body of the loop is executed first. The test condition is then evaluated. The control is transferred to the next statement if the value is false.

The body of the loop is executed repeatedly until the test condition becomes false. The control is transferred to the next statement if the test condition becomes false.

The general form is

do

{

body of the loop;

}

while(test condition);

next statement;

 

Example:

#include ,stdio.h>

main()

{

int j;

j=1;

do

{

printf(“welcome”);

j++;

}

while(j<5)

}

 

For statement

If the group of statement executed for a known number of times then we can use for a statement. The general form is

for(control variable; test condition; increment or decrement)

{

body of the loop;

}

next statement;

 

example:

#include ,stdio.h>

main()

{

int j,s;

s=0;

for(j=1;j<=100;j+)

{

s=s+i;

}

printf(“s=%d”,s);

}

Loop Statements Homework Help