What is Loop? And Type of Loop The university of Lahore Pakpattan campus
Definition of loop • Loops are used in programming to repeat a specific block of code until some end condition is met. There are three type of loops in C++ programming • for loop • while loop • Do while loop
for Loop Syntax in c++ for(initializationStatement; testExpression; updateStatement) { // codes }
How for loop works? 1.The initialization statement is executed only once at the beginning. 2.Then, the test expression is evaluated. 3.If the test expression is false, for loop is terminated. But if the test expression is true, codes inside body of for loop is executed and update expression is updated. 4.Again, the test expression is evaluated and this process repeats until the test expression is false.
Flowchart of for Loop in C++
Program of for Loop in C++
while loop The university of Lahore Pakpattan campus
While Loop Syntax in c++ while (testExpression) { // codes }
How while loop works? •The while loop evaluates the test expression. •If the test expression is true, codes inside the body of while loop is evaluated. •Then, the test expression is evaluated again. This process goes on until the test expression is false. •When the test expression is false, while loop is terminated.
FLOWCHART OF WHILE LOOP
C++ WHILE LOOP EXAMPLE
Do while loop The university of Lahore Pakpattan campus
DO WHILE LOOP SYNTAX IN C++ Do { // codes; } while (testExpression);
HOW DO...WHILE LOOP WORKS? •The codes inside the body of loop is executed at least once. Then, only the test expression is checked. •If the test expression is true, the body of loop is executed. This process continues until the test expression becomes false. •When the test expression is false, do...while loop is terminated.
FLOWCHART OF DO WHILE LOOP
C++ WHILE LOOP EXAMPLE
ANY QUESTIONS
types of loops and what is loop

types of loops and what is loop

  • 1.
    What is Loop?And Type of Loop The university of Lahore Pakpattan campus
  • 2.
    Definition of loop •Loops are used in programming to repeat a specific block of code until some end condition is met. There are three type of loops in C++ programming • for loop • while loop • Do while loop
  • 3.
    for Loop Syntaxin c++ for(initializationStatement; testExpression; updateStatement) { // codes }
  • 4.
    How for loopworks? 1.The initialization statement is executed only once at the beginning. 2.Then, the test expression is evaluated. 3.If the test expression is false, for loop is terminated. But if the test expression is true, codes inside body of for loop is executed and update expression is updated. 4.Again, the test expression is evaluated and this process repeats until the test expression is false.
  • 5.
    Flowchart of forLoop in C++
  • 6.
    Program of forLoop in C++
  • 7.
    while loop The universityof Lahore Pakpattan campus
  • 8.
    While Loop Syntaxin c++ while (testExpression) { // codes }
  • 9.
    How while loopworks? •The while loop evaluates the test expression. •If the test expression is true, codes inside the body of while loop is evaluated. •Then, the test expression is evaluated again. This process goes on until the test expression is false. •When the test expression is false, while loop is terminated.
  • 10.
  • 11.
  • 12.
    Do while loop Theuniversity of Lahore Pakpattan campus
  • 13.
    DO WHILE LOOPSYNTAX IN C++ Do { // codes; } while (testExpression);
  • 14.
    HOW DO...WHILE LOOPWORKS? •The codes inside the body of loop is executed at least once. Then, only the test expression is checked. •If the test expression is true, the body of loop is executed. This process continues until the test expression becomes false. •When the test expression is false, do...while loop is terminated.
  • 15.
    FLOWCHART OF DOWHILE LOOP
  • 16.
  • 17.