.

Loop Types in C++ Assignment Help

To execute the statements written inside the block is called loops. The statements are executed sequentially which means the order will not be changed that is first statement inside the block will be executed first. The statement inside the loop will be single or multiple statements which can be executed once or multiple numbers of times.

There are different types of loop types

  • For loop
  • While loop
  • Do-while loop

Loop Types in C++ Assignment Help By Online Tutoring and Guided Sessions from assignmenthippo.com


For loop

For loop is used as control statements which allows the loop to execute the statement within the block repeatedly for specific number of time. For loop statements will be executed again and again till the condition returns false. In for loop the statement is executed until the Boolean condition is false, once the condition is true the loop gets terminated. The structure of for loop is for followed by three statements initialization, condition and increment or decrement.

For Loop Syntax

    for(initialization; condition; increment or decrement )
    {
     //statement;
    }
    

Example Program

While loop

While loop is the control statement which executes the statement on the block if the condition is true. The condition in the loop is tested first then followed by the body of the loop which is called statements and is defined as entry-controlled loop.

Syntax:

loop types img1

Figure - Flowchart of while loop

Example

loop types img3

Figure : Flowchart for do while

Example

C++ Loop Control Statements

Loop control statements are used to change the normal sequence of execution of the loop.

Statement

Syntax

Description

break statement

break;

Is used to terminate loop or switch statements.

continue statement

continue;

Is used to suspend the execution of current loop iteration and transfer control to the loop for the next iteration.

goto statement

goto labelName;labelName: statement;

It transfers current program execution sequence to some other part of the program.

.