Skip to main content

9. Jumps Statement in c++

➢ Jumps in Loops:-

➢ C++ break and continue Statement:-

                There are two statements (break; and continue ;) built in C++ programming to alter the normal flow of program.

                Loops are used to perform repetitive task until test expression is false but sometimes it is desirable to skip some statement/s inside loop or terminate the loop immediately with checking test condition. On these type of scenarios, continue; statement and break; statement is used respectively. The break; statement is also used to terminate switch statement.


1) break Statement :-

                 The break; statement terminates the loop(for, while and do..while loop) and switch statement immediately when it appears .


Syntax of break :-


break;

                In real practice, break statement is almost always used inside the body of conditional statement(if...else) inside the loop.


2) continue Statement :-

                 It is sometimes necessary to skip some statement/s inside the loop. In that case, continue; statement is used in C++ programming.


Syntax of continue :-

 

continue;

                In practice, continue; statement is almost always used inside conditional statement.


Example Program:-


// C++ Program to demonstrate working of continue statement

// C++ program to display integer from 1 to 10 except 6 and 9.

#include <iostream.h>

#include <conio.h>

int main()

{

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

             {

                         if ( i == 6 || i == 9)

                         {

                                     continue;

                         }

                         cout<<i<<"\t";

             }

             getch();

}


Output :-

1 2 3 4 5 7 8 10


Comments

Popular posts from this blog

Remove specific item from Recyclerview in android studio

For Full video click on below link :- https://youtu.be/sUz4fqeanjI?si=A8AqBWCgu-5NnBOJ Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file.  <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" android:orientation="vertical" android:background="@color/white"> <EditText android:layout_width="350dp" android:layout_height="50dp" android:inputType="text" android:id="@+id/coursenam...

Fingerprint Authentication in Android Studio Project

Implement the implementation : - implementation 'androidx.biometric:biometric:1.0.1' Working with the activity_main.xml file. Navigate to the   app > res > layout > activity_main.xml  and add the below code to that file. Below is the code for the   activity_main.xml   file. <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:orientation="vertical" tools:context=".MainActivity" android:background="@color/white"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Welcome to the Boxcode!!" android:textSize=...

programming skills imp programs

Full course of c++ programming language Click here >  C++ programming language ===================================== 1. Write a program to display an average of 3 inputted numbers. a=int(input("Enter a : ")) b=int(input("Enter a : ")) c=int(input("Enter a : ")) avg=(a+b+c)/3 print(avg) ====================================== 2. Write a program to calculate simple interest for a given principle amount, rate of interest and no of years. p=float(input("Enter a P : ")) r=float(input("Enter a R : ")) n=float(input("Enter a N : ")) si=(p*r*n)/100 print("simple interest is ",si) ====================================== 3. Write a program to display area of triangle. base=float(input("Enter a base : ")) height=float(input("Enter a height : ")) area=base*height/2 print("Area of triangle is ",area) ====================================== 4. Write a program to calculate area of circle. r=float(input...