SlideShare a Scribd company logo
Topic
Swith
Break
executes
project report submitted by:-Sumit chauhan
submitted to :-Sawrna mam
class:-BCA 1st year
A switch statement allows a variable to be
tested for equality against a list of values.
Each value is called a case, and the variable
being switched on is checked for each switch
case.
10-Feb-20created by:-sumit
10-Feb-20
created by:-sumit
The syntax for a switch statement in C programming
language is as follows −
 switch(expression) {
 case constant-expression :
 statement(s);
 break; /* optional */
 case constant-expression :
 statement(s); break; /* optional */
 /* you can have any number of case statements */
 default : /* Optional */
 statement(s);
 }
 You can have any number of case statements within a
switch. Each case is followed by the value to be compared to
and a colon.
 The constant-expression for a case must be the same data type as
the variable in the switch, and it must be a constant or a literal
 When the variable being switched on is equal to a case, the
statements following that case will execute until
a break statement is reached.
 A switch statement can have an optional default case, which must
appear at the end of the switch. The default case can be used for
performing a task when none of the cases is true. No break is
needed in the default case.
10-Feb-20
created by:-sumit
10-Feb-20created by:-sumit
1. #include <stdio.h>
2. int main ()
3. {
4. char grade = 'B';
5. switch(grade)
6. {
7. case 'A' :
8. printf("Excellent!n"
);
9. break;
10. case 'B' :
11. case 'C' :
10-Feb-20created by:-sumit
12.printf("Well donen" );
13.break;
14.case 'D' :
15.printf("You passedn" );
16. break;
17.default :
18.printf("Invalid graden" );
}
19.printf("Your grade is %cn",
20.grade );
21. return 0;
}
Output:-Well done
Your grade is B
The break statement in C programming has the following two
usages −
 When a break statement is encountered inside a loop, the loop is
immediately terminated and the program control resumes at the next
statement following the loop.
 It can be used to terminate a case in the switch statement (covered in the
next chapter).
 If you are using nested loops, the break statement will stop the
execution of the innermost loop and start executing the next line of code
after the block.
10-Feb-20created by:-sumit
break;
Flow Diagram
10-Feb-20created by:-sumit
 #include <stdio.h>
 int main ()
 {
 int a = 10;
 /* while loop execution */
 while( a < 20 )
 {
 printf("value of a: %dn", a);
 a++;
 if( a > 15)
 {
 /* terminate the loop using break statement
*/
 break;
 }
 } return 0;
10-Feb-20created by:-sumit
Out out
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15
 This is basically the compilation process of a C program.
 The following diagram will show how a C Source Code can be executed.
10-Feb-20created by:-sumit
 C Code − This is the code that you have written. This
code is sent to the Preprocessors section.
10-Feb-20created by:-sumit
Preprocessing − In this section the preprocessor files are
attached with our code. We have use different header files
like stdio.h, math.h etc. These files are attached with the C
Source code and the final C Source generates. (‘#include’,
‘#define’ These are Preprocessor Directives.)
10-Feb-20created by:-sumit
Compiler − After generating the preprocessed source code, it moves
to the compiler and the compiler generates the assembly level code
after compiling the whole program.
Assembler − This part takes the assembly level language
from compiler and generates the Object code, this code is
quite similar to the machine code (set of binary digits).
10-Feb-20created by:-sumit
Linker − Linker is another important part of the compilation
process. It takes the object code and link it with other library
files, these library files are not the part of our code, but it helps
to execute the total program. After linking the Linker
generates the final Machine code which is ready to execute.
Loader − A program, will not be executed until it is not
loaded in to Primary memory. Loader helps to load the
machine code to RAM and helps to execute it. While
executing the program is named as Process. So process is
(Program in execution).
10-Feb-20
created by:-sumit

More Related Content

What's hot

Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch cases
MeoRamos
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
bsdeol28
 

What's hot (13)

My first program in c, hello world !
My first program in c, hello world !My first program in c, hello world !
My first program in c, hello world !
 
selection structures
selection structuresselection structures
selection structures
 
Cinfo
CinfoCinfo
Cinfo
 
Introduction of C#
Introduction of C#Introduction of C#
Introduction of C#
 
Template classes and ROS messages
Template classes and ROS messagesTemplate classes and ROS messages
Template classes and ROS messages
 
Verilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONSVerilog TASKS & FUNCTIONS
Verilog TASKS & FUNCTIONS
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Looping and switch cases
Looping and switch casesLooping and switch cases
Looping and switch cases
 
Ref cursor
Ref cursorRef cursor
Ref cursor
 
Loops c++
Loops c++Loops c++
Loops c++
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Presentation on nesting of loops
Presentation on nesting of loopsPresentation on nesting of loops
Presentation on nesting of loops
 

Similar to switch,break,.........

C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
AashutoshChhedavi
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
LynellBull52
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
RSathyaPriyaCSEKIOT
 

Similar to switch,break,......... (20)

Decision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, StringsDecision Making Statements, Arrays, Strings
Decision Making Statements, Arrays, Strings
 
Basic construction of c
Basic construction of cBasic construction of c
Basic construction of c
 
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptxIIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
IIM.Com-FIT-Unit2(14.9.2021 TO 30.9.2021).pptx
 
C Introduction and bascis of high level programming
C Introduction and bascis of high level programmingC Introduction and bascis of high level programming
C Introduction and bascis of high level programming
 
Programming in C
Programming in CProgramming in C
Programming in C
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Presentation 2
Presentation 2Presentation 2
Presentation 2
 
Looping statements
Looping statementsLooping statements
Looping statements
 
C introduction
C introductionC introduction
C introduction
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentation
 
C programming
C programmingC programming
C programming
 
C notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-semC notes diploma-ee-3rd-sem
C notes diploma-ee-3rd-sem
 
C programming
C programmingC programming
C programming
 
C language introduction geeksfor geeks
C language introduction   geeksfor geeksC language introduction   geeksfor geeks
C language introduction geeksfor geeks
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
 
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
UNIT-1 notes(Data Types – Variables – Operations – Expressions and Statements...
 
Bitstuffing
BitstuffingBitstuffing
Bitstuffing
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 

Recently uploaded

The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
heathfieldcps1
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
Avinash Rai
 

Recently uploaded (20)

Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).Dementia (Alzheimer & vasular dementia).
Dementia (Alzheimer & vasular dementia).
 
The basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptxThe basics of sentences session 4pptx.pptx
The basics of sentences session 4pptx.pptx
 
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
Removal Strategy _ FEFO _ Working with Perishable Products in Odoo 17
 
Open Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPointOpen Educational Resources Primer PowerPoint
Open Educational Resources Primer PowerPoint
 
....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf....................Muslim-Law notes.pdf
....................Muslim-Law notes.pdf
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 2 STEPS Using Odoo 17
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...The impact of social media on mental health and well-being has been a topic o...
The impact of social media on mental health and well-being has been a topic o...
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General QuizPragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
Pragya Champions Chalice 2024 Prelims & Finals Q/A set, General Quiz
 
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdfPost Exam Fun(da) Intra UEM General Quiz - Finals.pdf
Post Exam Fun(da) Intra UEM General Quiz - Finals.pdf
 

switch,break,.........

  • 1. Topic Swith Break executes project report submitted by:-Sumit chauhan submitted to :-Sawrna mam class:-BCA 1st year
  • 2. A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case. 10-Feb-20created by:-sumit
  • 3. 10-Feb-20 created by:-sumit The syntax for a switch statement in C programming language is as follows −  switch(expression) {  case constant-expression :  statement(s);  break; /* optional */  case constant-expression :  statement(s); break; /* optional */  /* you can have any number of case statements */  default : /* Optional */  statement(s);  }
  • 4.  You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon.  The constant-expression for a case must be the same data type as the variable in the switch, and it must be a constant or a literal  When the variable being switched on is equal to a case, the statements following that case will execute until a break statement is reached.  A switch statement can have an optional default case, which must appear at the end of the switch. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case. 10-Feb-20 created by:-sumit
  • 6. 1. #include <stdio.h> 2. int main () 3. { 4. char grade = 'B'; 5. switch(grade) 6. { 7. case 'A' : 8. printf("Excellent!n" ); 9. break; 10. case 'B' : 11. case 'C' : 10-Feb-20created by:-sumit 12.printf("Well donen" ); 13.break; 14.case 'D' : 15.printf("You passedn" ); 16. break; 17.default : 18.printf("Invalid graden" ); } 19.printf("Your grade is %cn", 20.grade ); 21. return 0; } Output:-Well done Your grade is B
  • 7. The break statement in C programming has the following two usages −  When a break statement is encountered inside a loop, the loop is immediately terminated and the program control resumes at the next statement following the loop.  It can be used to terminate a case in the switch statement (covered in the next chapter).  If you are using nested loops, the break statement will stop the execution of the innermost loop and start executing the next line of code after the block. 10-Feb-20created by:-sumit
  • 9.  #include <stdio.h>  int main ()  {  int a = 10;  /* while loop execution */  while( a < 20 )  {  printf("value of a: %dn", a);  a++;  if( a > 15)  {  /* terminate the loop using break statement */  break;  }  } return 0; 10-Feb-20created by:-sumit Out out value of a: 10 value of a: 11 value of a: 12 value of a: 13 value of a: 14 value of a: 15
  • 10.  This is basically the compilation process of a C program.  The following diagram will show how a C Source Code can be executed. 10-Feb-20created by:-sumit
  • 11.  C Code − This is the code that you have written. This code is sent to the Preprocessors section. 10-Feb-20created by:-sumit Preprocessing − In this section the preprocessor files are attached with our code. We have use different header files like stdio.h, math.h etc. These files are attached with the C Source code and the final C Source generates. (‘#include’, ‘#define’ These are Preprocessor Directives.)
  • 12. 10-Feb-20created by:-sumit Compiler − After generating the preprocessed source code, it moves to the compiler and the compiler generates the assembly level code after compiling the whole program. Assembler − This part takes the assembly level language from compiler and generates the Object code, this code is quite similar to the machine code (set of binary digits).
  • 13. 10-Feb-20created by:-sumit Linker − Linker is another important part of the compilation process. It takes the object code and link it with other library files, these library files are not the part of our code, but it helps to execute the total program. After linking the Linker generates the final Machine code which is ready to execute. Loader − A program, will not be executed until it is not loaded in to Primary memory. Loader helps to load the machine code to RAM and helps to execute it. While executing the program is named as Process. So process is (Program in execution).