0% found this document useful (0 votes)
11 views8 pages

Jump Stetments

The document explains the use of the break and continue statements in loop structures such as for and while loops. The break statement terminates the loop immediately, while the continue statement skips the current iteration and continues with the next one. Examples are provided to illustrate how each statement functions in practice.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Jump Stetments

The document explains the use of the break and continue statements in loop structures such as for and while loops. The break statement terminates the loop immediately, while the continue statement skips the current iteration and continues with the next one. Examples are provided to illustrate how each statement functions in practice.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 8

Loops

The break and continue statements


Introduction

• There are 2 special statements that can affect the execution


of loop statements (such as for or while-statement)
• The special statements are:

• break
• continue

We will study their meaning and how to use these special


statements inside the while-statement
The break statement
• Syntax:

break;
Effect:
• When the break statement is executed inside a loop-
statement, the loop-statement is terminated
immediately
• The execution of the program will continue with the
statement following the loop-statement
Example:

//print the number, as soon as, you see 5 terminate the loop

for(int i=1; i<=10; i++)


{
if(i==5)
{
break;
}
cout<<i;
}
}
run:
1234
The break statement (cont.)

• Schematically:
The continue statement

• Syntax:

continue;

• Continue statement or known as jump


statement is used to skip a number and
continue after that point
The continue statement (cont.)

• Schematically:
Example-1: print all the numbers from 1 to 10 except 4 .
#include "q3.h"
#include <iostream>
#include <iomanip>
using namespace std;
q3::q3()
{
for (int i = 1; i <=10; i++)
{
if(i==4)

continue;
cout<<i<<endl;
}
}

Example-2: prints all the numbers from 1 to 10 except 5 and 6.


for (int i = 1; i <=8; i++)
{
if(i>4 && i<7)
continue;
cout<<i<<endl;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy