Skip to main content

Loops in C++

Loops and Jump Statements

Loops

Loop is a block of code or sequence of statements which repeates until a specific condition statisfied. There are 3 types of Loops in C++
  1. while()
  2. do...while()
  3. for()
    • Nested for()

While Loop

While Loop is also known as Entry Control Loop.
In while loop the Condition is checked before entering into the Loop if the condition is true then it will execute the statements otherwise terminates the Loop.

Syntax

while(condition)
{
Statements;
inc/dec;
}

do..While Loop

do..While Loop is also known as Exit Control Loop.
In do..while loop the condition is checked after Executing the statement once.
It will execute the statements once even the condition is false.

Syntax

do
{
Statements;
inc/dec;
}while(condition);

for Loop

for Loop is Used to reduce the Line of code in program.
In for loop the initialization, condition and increment/decrement is given in a single line.

Syntax

for(initialization; condition; inc/dec)
{
Statements;
}
-----------------------------------------------------------------------------------------------------------------

initialization;
for(; condition; inc/dec)
{
Statements;
}

-----------------------------------------------------------------------------------------------------------------

initialization;
for(; condition; )
{
Statements;
inc/dec;
}

-----------------------------------------------------------------------------------------------------------------
for Infinite Loop
for(; ; )
{
Statements;

}

Nested for Loop

Nested for loop is a loop which is used inside another loop.
There is an Outer loop and an Inner Loop. Where if the Condition of Outer loop is true then will execute the Inner Loop. Otherwise Terminates the Loop.

Syntax

for(initializaion; condition; inc/dec)
{
for(initializaion; condition; inc/dec)
{
Statements;
}
}

Programs

while loop

Write a Program to print "Programming World!!" 10 times.


























do while loop

Write a Program to print number from 10-1.

























for Loop

Write a Program to print Table of any number using For Loop.

























Nested for Loop




  • Write a Program to print Following Pattern.
  •  *
    * *
    * * *
    * * * *
    * * * * *


















    Jump Statements

    break statement:

    break statements is used to stop the execution of a particular block.
    It can be used with Conditional Statements as well as Loops.

    Program

    Write a Program to show the used of break keyword.

















    continue statement:

    continue statements is used with loops where continue is used to skip the particular staement at a given condition.

    Program

    Write a program to print numbers from 1-50 and skip the numbers which are dicisible by 9

















    goto Statement

    It is a type of jump statement use to jump from one statement to another.

    Syntax

     goto label;
                        - - - - - - - - - -
                        - - - - - - - - - -
                  label:
                        - - - - - - - - - -
                        - - - - - - - - - -
    Write a program to show the use of goto statements





    Comments

    Popular posts from this blog

    Programming Basics

    Logic Building Data_Types Operators Algorithms Pseudo_Code Hello Guys, Let's Play with Logic.........but wait, before that you must know that how to build Logic in Programming as you all know that programming is all about Logic..... So Let's start the game... If you are new Here that means you are absolutely right Place, Or If you already know, than you will learn new things here! If we Talk about the Programming we should be familiar with  these terms..... 1. Variable 2. Data Types 3.Keywords Variable: Variable is something which holds the value.                  Like:      a=10;                 Here,                 a---------------------->  Variable                  10 ---------------------> Value * The Value of Variable can be changed , *  " Variable is a named memory Location which holds a value." Data Types:   Data Type is what which tells that which kind of data we are using. In programming we have different Dat

    FAQs

    Basic Questions on Programming Languages 1. What is the meaning of Programming? Ans: Programming is the process of Scheduling the task to perform step by step to Execute a specific Task. 2. Types of Programming Languages? Ans: Types:             Procedural Programming Language            Object Oriented Programming Language            Object Based Language            Scripting Language Procedural Programming Language   C Programming  Object Oriented Programming Language     C++     Java     C#     VB.Net Object Based Language     JavaScript Scripting Language     Python     VBScript     PHP     Perl     Ruby     R 3. Types Of Operators in Programming Languages. Ans:      Operators Symbols Type Example Assignment = Unary a=10 Arithmetic +,-,/,*,% Binary a+b  a-b  a*b  a/b  a%b Relational >, <, >=, <=, ==, !=(Not Equal) Binary It gives Result in Boolen value True/False a>b  a<b  a>=b  a<=b  a==b  a!=b Logical && (AND), ||(OR), !(Not) Binary It gives Resul