SlideShare a Scribd company logo
CONSTRUCTS
(IMPERATIVE PROGRAMMING
LANGUAGE)
Selection Constructs
Conditional Constructs
Looping Constructs
By: Jyoti Bhardwaj
Roll no: 04
F.Y. M.C.A
SELECTION CONSTRUCTS.
THE SELECTION CONSTRUCT:
The selection construct allows you to create a program that will select one of a
number of different alternative courses of action. It is also called the if..then..else
construct.
 A selection statement provides for selection between alternatives. We can identify two
types of selection constructs:
 If statements
 Case statements
IF STATEMENT:
 An if statement, sometimes referred to as a conditional, can be used in two forms:
 If condition then action1
if (condition1) action1;
if (condition2) action2;
.
.
.
if (conditionN) actionN;
 If condition then action1 else action2
if... else example
main()
{
int i;
printf("nEnter a number : ");
scanf("%d",&i);
if( i > 7 )
printf("I is greater than seven");
else
printf("I is not greater than seven");
}
Output:
Enter a number: 5
I is not greater than seven
CASE STATEMENT:
 Switch case statements are a substitute for long if statements that
compare a variable to several values. Case statements allow selection
from many alternatives.
 The switch expression is evaluated once.
 The value of the expression is compared with the values of each case.
 If there is a match, the associated block of code is executed.
Using break keyword:
 If a condition is met in switch case then execution continues on into
the next case clause also if it is not explicitly specified that the
execution should exit the switch statement.This is achieved by
using break keyword.
What is default condition:
 If none of the listed conditions is met then default condition
executed.
The basic format for using switch case is outlined below:
switch(expression)
{
case 1:
code block
break;
case 2:
code block
break;
.
.
case n:
code block
break;
default:
default code block
}
Selection structure vary from language to language,
but they tend to agree on the following:
 Case Selection can appear in any order.
 Case Selections do not have to be consecutive, meaning that it is
valid to have case-1, and case-4 without case-2 and case-3.
 Case Selection must have distinct actions for each case,
otherwise we need to combine the actions to avoid conflict.
To Sum up, the effect of Switch structure is as follows:
 Evaluate the switch expression.
 Go to the case label having a constant value that matches the
value of the expression found in step 1; If a match is found, go
to the default label; if there is no default label; terminate the
switch.
 Terminate the switch when break statement in encountered.
Switch… case example:
main()
{
int Grade = 'B';
switch(Grade )
{
case 'A' : printf( "Excellentn" );
break;
case 'B' : printf( “Very Goodn" );
break;
case 'C' : printf( "Good n" );
break;
case 'D' : printf( “O.K. n" );
break;
case 'F' : printf( “Satisfactory n" );
break;
default : printf( “Fair n" );
break;
}
}
This will produce following result:
Good
CONDITIONALCONSTRUCTS.
 The conditional construct allows you to create a program that
will select one of a number of different alternative courses of
action. It is also called the if..then..else construct.
 The initial if statement checks a condition (in this case >= 50).
If the condition is true, then the series of commands following
it are executed. If the condition is false (i.e. the user enters a
mark less than 50), then the series of commands following the
else statement are executed.
Note:
 An if statement must check a condition and then be followed
by the word then.
 An if statement must have an end if to finish it off.
 An if statement does not have to have an else statement.
If…else Ladder:
if (expression)
{
Block of statements;
}
else
{
Block of statements;
}
if (expression)
{
Block of
statements;
}
else if(expression)
{
Block of
statements;
}
else
{
Block of
statements;
}
If…else Ladder:
if... else example
int main()
{
int year;
printf("Enter a year: ");
scanf("%d",&year);
if(year%4 == 0)
{
if( year%100 == 0)
{
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);
return 0;
}
LOOPINGCONSTRUCTS:
The loop constructs is
used to execute a block
of code until the
condition becomes
expired.
Loop constructs saves
the programmer from
writing code multiple
times that has
repetitive in nature
Types of loop to handle looping requirements
LoopType Description
 while loop Repeats a statement or group of
statements while a given condition
is true. It tests the condition before
executing the loop body.
 for loop Execute a sequence of statements
multiple times.
 do...while loop Like a while statement, except that it
tests the condition at the end of the
loop body
 nested loops You can use one or more loop inside
any another while, for or do..while
loop.
The Infinite Loop:
 A loop becomes infinite loop if a condition never
becomes false.The for loop is traditionally used for this
purpose. Since none of the three expressions that form
the for loop are required, you can make an endless
loop by leaving the conditional expression empty.
 int main ()
{
for( ; ; )
{
printf("This loop will run forever.n");
}
return 0;
}
While loop example..
 In while loop control statement, loop is executed until condition becomes false.
 Syntax:
while( condition )
body;
 int main()
{
int i=3;
while(i<10)
{
printf("%dn",i); i++;
}
}
Output:
3 4 5 6 7 8 9
do...while loop examples
 In do..while loop control statement, while loop is executed irrespective of
the condition for first time. Then 2nd time onwards, loop is executed until
condition becomes false.
 int main()
{
int i=1;
do
{
printf("Value of i is %dn",i);
i++;
}
while(i<=4 && i>=2);
}
Output:
Value of i is 1
Value of i is 2
Value of i is 3
Value of i is 4
For loop example.
In for loop control statement, loop is executed until condition becomes false.
 int main()
{
int i;
for(i=0;i<10;i++)
{
printf("%d ",i);
}
}
Output:
0 1 2 3 4 5 6 7 8 9
WhentoUseWhichLoop?
Ifyouknow(orcancalculate)
howmanyiterationsyouneed,
thenuseacounter-controlled(for
)loop.
Otherwise,ifitisimportantthat
theloopcompleteatleastonce
beforecheckingforthestopping
condition,
orifitisnotpossibleor
meaningfultocheckthestopping
conditionbeforetheloophas
executedatleastonce,
thenuseado-whileloop.
Otherwiseuseawhileloop.
Constructs (Programming Methodology)

More Related Content

What's hot

Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
amber chaudary
 
Core Java Equals and hash code
Core Java Equals and hash codeCore Java Equals and hash code
Core Java Equals and hash code
mhtspvtltd
 
10. switch case
10. switch case10. switch case
10. switch case
Way2itech
 
Java Networking
Java NetworkingJava Networking
Java Networking
Sunil OS
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
Way2itech
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
Ahsan Raja
 
Looping in c language
Looping in c languageLooping in c language
Looping in c language
Infinity Tech Solutions
 
Simple object access protocol(soap )
Simple object access protocol(soap )Simple object access protocol(soap )
Simple object access protocol(soap )
balamurugan.k Kalibalamurugan
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
Mukesh Tekwani
 
VB Script
VB ScriptVB Script
VB Script
Satish Sukumaran
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
4. THREE DIMENSIONAL DISPLAY METHODS
4.	THREE DIMENSIONAL DISPLAY METHODS4.	THREE DIMENSIONAL DISPLAY METHODS
4. THREE DIMENSIONAL DISPLAY METHODS
SanthiNivas
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
If and select statement
If and select statementIf and select statement
If and select statement
Rahul Sharma
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Mohammad Ilyas Malik
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
Mushiii
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
Taha Malampatti
 

What's hot (20)

Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Core Java Equals and hash code
Core Java Equals and hash codeCore Java Equals and hash code
Core Java Equals and hash code
 
OOP java
OOP javaOOP java
OOP java
 
10. switch case
10. switch case10. switch case
10. switch case
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Polymorphism presentation in java
Polymorphism presentation in javaPolymorphism presentation in java
Polymorphism presentation in java
 
Looping in c language
Looping in c languageLooping in c language
Looping in c language
 
Simple object access protocol(soap )
Simple object access protocol(soap )Simple object access protocol(soap )
Simple object access protocol(soap )
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Finite Automata
Finite AutomataFinite Automata
Finite Automata
 
VB Script
VB ScriptVB Script
VB Script
 
Interface in java
Interface in javaInterface in java
Interface in java
 
4. THREE DIMENSIONAL DISPLAY METHODS
4.	THREE DIMENSIONAL DISPLAY METHODS4.	THREE DIMENSIONAL DISPLAY METHODS
4. THREE DIMENSIONAL DISPLAY METHODS
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
If and select statement
If and select statementIf and select statement
If and select statement
 
The structure of agents
The structure of agentsThe structure of agents
The structure of agents
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
 
Loops Basics
Loops BasicsLoops Basics
Loops Basics
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Viewers also liked

4 c# programming constructs
4   c# programming constructs4   c# programming constructs
4 c# programming constructsTuan Ngo
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
Eduardo Bergavera
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
akmalfahmi
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
trupti1976
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
rajni kaushal
 
Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]
Abdullah khawar
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
Eduardo Bergavera
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramDeepak Singh
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
Loop c++
Loop c++Loop c++
Loop c++
Mood Mood
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
طارق بالحارث
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
Appili Vamsi Krishna
 
Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodology
archikabhatia
 
Array in c++
Array in c++Array in c++
Array in c++
Mahesha Mano
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
Farhan Ab Rahman
 

Viewers also liked (20)

4 c# programming constructs
4   c# programming constructs4   c# programming constructs
4 c# programming constructs
 
UNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming ConstructsUNIX - Class3 - Programming Constructs
UNIX - Class3 - Programming Constructs
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
Chapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and PolymorphismChapter 13 - Inheritance and Polymorphism
Chapter 13 - Inheritance and Polymorphism
 
8.3 program structure (1 hour)
8.3 program structure (1 hour)8.3 program structure (1 hour)
8.3 program structure (1 hour)
 
CP Handout#5
CP Handout#5CP Handout#5
CP Handout#5
 
Java programming lab assignments
Java programming lab assignments Java programming lab assignments
Java programming lab assignments
 
Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]Pf cs102 programming-9 [pointers]
Pf cs102 programming-9 [pointers]
 
Apclass
ApclassApclass
Apclass
 
Apclass (2)
Apclass (2)Apclass (2)
Apclass (2)
 
Chapter 12 - File Input and Output
Chapter 12 - File Input and OutputChapter 12 - File Input and Output
Chapter 12 - File Input and Output
 
Chapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ ProgramChapter 2 - Structure of C++ Program
Chapter 2 - Structure of C++ Program
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodology
 
Loop c++
Loop c++Loop c++
Loop c++
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
User defined functions in C programmig
User defined functions in C programmigUser defined functions in C programmig
User defined functions in C programmig
 
Programming Methodology
Programming MethodologyProgramming Methodology
Programming Methodology
 
Array in c++
Array in c++Array in c++
Array in c++
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 

Similar to Constructs (Programming Methodology)

Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
Saad Sheikh
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
Jayfee Ramos
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
Ujwala Junghare
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
TejaswiB4
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
University of Potsdam
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptx
Ujwala Junghare
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
Tanmay Modi
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
tanmaymodi4
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
TANUJ ⠀
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
Thesis Scientist Private Limited
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
RAJ KUMAR
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
chintupro9
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
MURALIDHAR R
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionalish sha
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Chandrakant Divate
 
Control statements
Control statementsControl statements
Control statements
CutyChhaya
 

Similar to Constructs (Programming Methodology) (20)

Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Java Decision Control
Java Decision ControlJava Decision Control
Java Decision Control
 
BSc. III Unit iii VB.NET
BSc. III Unit iii VB.NETBSc. III Unit iii VB.NET
BSc. III Unit iii VB.NET
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Chapter 4(1)
Chapter 4(1)Chapter 4(1)
Chapter 4(1)
 
Control Statement programming
Control Statement programmingControl Statement programming
Control Statement programming
 
Unit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptxUnit IV Array in VB.Net.pptx
Unit IV Array in VB.Net.pptx
 
Decision statements in c laguage
Decision statements in c laguageDecision statements in c laguage
Decision statements in c laguage
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
 
Flow of control C ++ By TANUJ
Flow of control C ++ By TANUJFlow of control C ++ By TANUJ
Flow of control C ++ By TANUJ
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
Decision Making and Branching in C
Decision Making and Branching  in CDecision Making and Branching  in C
Decision Making and Branching in C
 
C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)C Constructs (C Statements & Loop)
C Constructs (C Statements & Loop)
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Dti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selectionDti2143 chap 4 control structures aka_selection
Dti2143 chap 4 control structures aka_selection
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Control statements
Control statementsControl statements
Control statements
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 

Constructs (Programming Methodology)

  • 1. CONSTRUCTS (IMPERATIVE PROGRAMMING LANGUAGE) Selection Constructs Conditional Constructs Looping Constructs By: Jyoti Bhardwaj Roll no: 04 F.Y. M.C.A
  • 2. SELECTION CONSTRUCTS. THE SELECTION CONSTRUCT: The selection construct allows you to create a program that will select one of a number of different alternative courses of action. It is also called the if..then..else construct.  A selection statement provides for selection between alternatives. We can identify two types of selection constructs:  If statements  Case statements IF STATEMENT:  An if statement, sometimes referred to as a conditional, can be used in two forms:  If condition then action1 if (condition1) action1; if (condition2) action2; . . . if (conditionN) actionN;  If condition then action1 else action2
  • 3. if... else example main() { int i; printf("nEnter a number : "); scanf("%d",&i); if( i > 7 ) printf("I is greater than seven"); else printf("I is not greater than seven"); } Output: Enter a number: 5 I is not greater than seven
  • 4. CASE STATEMENT:  Switch case statements are a substitute for long if statements that compare a variable to several values. Case statements allow selection from many alternatives.  The switch expression is evaluated once.  The value of the expression is compared with the values of each case.  If there is a match, the associated block of code is executed. Using break keyword:  If a condition is met in switch case then execution continues on into the next case clause also if it is not explicitly specified that the execution should exit the switch statement.This is achieved by using break keyword. What is default condition:  If none of the listed conditions is met then default condition executed.
  • 5. The basic format for using switch case is outlined below: switch(expression) { case 1: code block break; case 2: code block break; . . case n: code block break; default: default code block }
  • 6. Selection structure vary from language to language, but they tend to agree on the following:  Case Selection can appear in any order.  Case Selections do not have to be consecutive, meaning that it is valid to have case-1, and case-4 without case-2 and case-3.  Case Selection must have distinct actions for each case, otherwise we need to combine the actions to avoid conflict. To Sum up, the effect of Switch structure is as follows:  Evaluate the switch expression.  Go to the case label having a constant value that matches the value of the expression found in step 1; If a match is found, go to the default label; if there is no default label; terminate the switch.  Terminate the switch when break statement in encountered.
  • 7. Switch… case example: main() { int Grade = 'B'; switch(Grade ) { case 'A' : printf( "Excellentn" ); break; case 'B' : printf( “Very Goodn" ); break; case 'C' : printf( "Good n" ); break; case 'D' : printf( “O.K. n" ); break; case 'F' : printf( “Satisfactory n" ); break; default : printf( “Fair n" ); break; } } This will produce following result: Good
  • 8. CONDITIONALCONSTRUCTS.  The conditional construct allows you to create a program that will select one of a number of different alternative courses of action. It is also called the if..then..else construct.  The initial if statement checks a condition (in this case >= 50). If the condition is true, then the series of commands following it are executed. If the condition is false (i.e. the user enters a mark less than 50), then the series of commands following the else statement are executed. Note:  An if statement must check a condition and then be followed by the word then.  An if statement must have an end if to finish it off.  An if statement does not have to have an else statement.
  • 9. If…else Ladder: if (expression) { Block of statements; } else { Block of statements; } if (expression) { Block of statements; } else if(expression) { Block of statements; } else { Block of statements; }
  • 11. if... else example int main() { int year; printf("Enter a year: "); scanf("%d",&year); if(year%4 == 0) { if( year%100 == 0) { if ( year%400 == 0) printf("%d is a leap year.", year); else printf("%d is not a leap year.", year); } else printf("%d is a leap year.", year ); } else printf("%d is not a leap year.", year); return 0; }
  • 12. LOOPINGCONSTRUCTS: The loop constructs is used to execute a block of code until the condition becomes expired. Loop constructs saves the programmer from writing code multiple times that has repetitive in nature
  • 13. Types of loop to handle looping requirements LoopType Description  while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body.  for loop Execute a sequence of statements multiple times.  do...while loop Like a while statement, except that it tests the condition at the end of the loop body  nested loops You can use one or more loop inside any another while, for or do..while loop.
  • 14. The Infinite Loop:  A loop becomes infinite loop if a condition never becomes false.The for loop is traditionally used for this purpose. Since none of the three expressions that form the for loop are required, you can make an endless loop by leaving the conditional expression empty.  int main () { for( ; ; ) { printf("This loop will run forever.n"); } return 0; }
  • 15. While loop example..  In while loop control statement, loop is executed until condition becomes false.  Syntax: while( condition ) body;  int main() { int i=3; while(i<10) { printf("%dn",i); i++; } } Output: 3 4 5 6 7 8 9
  • 16. do...while loop examples  In do..while loop control statement, while loop is executed irrespective of the condition for first time. Then 2nd time onwards, loop is executed until condition becomes false.  int main() { int i=1; do { printf("Value of i is %dn",i); i++; } while(i<=4 && i>=2); } Output: Value of i is 1 Value of i is 2 Value of i is 3 Value of i is 4
  • 17. For loop example. In for loop control statement, loop is executed until condition becomes false.  int main() { int i; for(i=0;i<10;i++) { printf("%d ",i); } } Output: 0 1 2 3 4 5 6 7 8 9