COM1407: Program Control Structures – Decision Making & BranchingHemantha Kulathilake
At the end of this lecture students should be able to;
Define the operation of if, if-else, nested if-else, switch and conditional operator.
Justify the control flow of the program under the aforementioned C language constructs.
Apply taught concepts for writing programs.
This document discusses flow control in C programming. It covers:
1. Control structures like sequence, selection, and repetition that regulate program execution flow. Selection uses if/else statements to make decisions while repetition uses loops.
2. Boolean expressions that evaluate to true or false, including relational expressions comparing values and logical expressions combining conditions.
3. The if and if/else selection structures for conditional execution including syntax, truth tables for logical operators, and nested conditional structures.
4. The switch multiple-selection structure for testing a variable against multiple values through case labels and an optional default. It must end each case with a break to avoid fall-through.
This page contains examples and source code on decision making in C programming (to choose a particular statement among many statements) and loops ( to perform repeated task ). To understand all the examples on this page, you should have knowledge of following topics:
if...else Statement
for Loop
while Loop
break and Continue Statement
switch...case
The document discusses various control structures in C language that are used to control the flow of execution in a program. It explains the three types of execution flow as sequence, selection, and repetition. Under selection it covers if, if-else, if-else-if, switch statements. Under repetition it covers while, do-while, for loops. For each control structure, it provides syntax, examples and explanations.
The document discusses different types of selection and looping constructs in imperative programming languages. It describes if-else statements, switch-case statements, and how they allow a program to select different courses of action based on conditions. It also covers while, for, and do-while loops and how they repeatedly execute blocks of code while or until certain conditions are met. Examples are provided for each type of construct to illustrate their syntax and usage.
This document discusses various control structures in programming like if-else statements, switch statements, and loops. It provides syntax and examples of using if-else statements to execute code conditionally based on simple or nested conditions. Switch statements allow selecting between multiple code blocks based on a variable's value. Loops like for, while, and do-while loops are covered, which allow repetitive execution of code. The break and continue statements are also introduced to control loop flow. Examples are provided to demonstrate different control structures for problems like finding largest of numbers, checking positive/negative/zero, and character input validation.
This document discusses flow of control in C programming. It covers selection structures like if/else statements that allow a program to make decisions based on boolean expressions. It also covers repetition structures like loops. The key control structures are sequences, selection, and repetition. Selection structures include if/else and switch statements. If/else allows two alternative paths, while switch supports multiple comparisons. Logical and relational operators are used to construct boolean expressions that if/else and switch evaluate. Proper indentation and braces are important for nested conditional statements.
Decision Making Statements, Arrays, StringsPrabu U
The document discusses various decision making and looping statements in C programming language. It describes if, if-else, nested if, switch statements for decision making. It also covers while, for, do-while and nested loops for looping/iteration. Examples are provided for each statement to illustrate their syntax and usage. Arrays, functions, recursion and passing arrays to functions are also mentioned as topics to be covered.
The document discusses various control structures in C programming, including selection and repetition structures. It covers conditional statements like if, if-else, if-else-if, nested if, and switch statements. These allow altering the flow of execution based on certain conditions. The if statement and if-else statement are used for simple conditional execution, while if-else-if is used to check multiple conditions. Nested if allows if statements within other if statements. Finally, the switch statement provides another way to conditionally execute code based on different case options.
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
The document discusses different types of flow control in programming including sequential, selection, and repetition structures. It provides examples of if/else statements, nested ifs, if-else ladders, and the conditional operator. It also covers switch-case statements as an alternative for complex decisions. Finally, it poses challenges for readers to code decision-making structures using if/else and switch-case statements.
1. C programs consist of functions that perform specific tasks. The main() function is where program execution begins.
2. This example program prints "Welcome to C" by using functions like printf() to output text and getch() to pause the program.
3. The #include directives tell the compiler to include header files containing declarations for functions like printf() and clrscr() that are used in the program.
The document discusses various conditional control statements in C language including if, if-else, nested if, if-else-if, switch case statements. It provides the syntax and examples for each statement. Key conditional control statements covered are:
1) if statement - Executes code if a condition is true.
2) if-else statement - Executes one block of code if condition is true and another if false.
3) Nested if statements - if statements within other if statements allow multiple conditions to be checked.
4) if-else-if statement - Allows multiple alternative blocks to be executed depending on different conditions.
5) switch case statement - Allows efficient selection from multiple discrete choices
The document discusses various decision making statements in C programming language including if, if-else, if-else-ladder, nested if-else, switch-case, goto, break, continue statements. It provides examples and explanations of how each statement works. Key decision making statements covered are if, if-else for simple conditions, if-else-ladder for multiple conditions, switch-case for choices, and goto for unconditional branching.
3-Conditional-if-else-switch btech computer in c.pdfArkSingh7
This document discusses conditional statements and branching in programming. It explains how conditional statements like if-else and switch statements allow programs to execute different blocks of code depending on logical conditions. The if statement and if-else statement are used to check conditions and branch the execution accordingly. The switch statement provides an alternative way to write multiple conditional checks using case labels. Break statements are used to terminate the execution of a switch or loop.
The document provides information on C programming concepts including data types, operators, control structures, and loops. It includes code examples to demonstrate printf() and scanf() functions, if/else conditional statements, while and for loops. It also defines relational, logical, and ternary operators and explains the three basic control structures: sequence, selection, and iteration. Key concepts around while, do-while, for loops and switch/case statements are described.
The document discusses conditional statements and flow control in C programming. It explains if, if-else, nested if, and comparison operators. Examples are provided to illustrate if statements to check even/odd numbers, grades passed/failed, guessing a secret number, checking alphabet characters, and finding the maximum of three numbers. Nested if statements can check multiple conditions. Conditional statements allow programmers to execute code conditionally based on boolean expressions evaluating to true or false.
Chap7_b Control Statement Looping (3).pptxFakhriyArif
The document discusses control statements in C programming, specifically if, if-else, and if-else-if statements. It provides the syntax and examples of using these conditional statements to execute code based on expression evaluations. It also covers nested if statements, when else clauses are attached, and the importance of brackets. The document then discusses the switch statement, providing syntax and an example to print the name of a month based on a number input. It emphasizes the need for break statements to terminate each case.
The document discusses various control statements in C programming such as if, if-else, nested if, switch case, break, continue, and goto statements. It provides the syntax and examples of using each statement. Key control statements covered include:
- if statement which executes code if a condition is true
- if-else statement which allows executing one code block if a condition is true and another if it is false
- nested if statements which allow logical conditions to be checked within other if blocks
- switch case statement which allows a variable to be tested against multiple values and execute the corresponding code block
This document provides an overview of key concepts in C programming including algorithms, flowcharts, operations and variables, conditional statements like if-else, switch case, loops like for, while, do-while. It includes examples to demonstrate printf, scanf, arithmetic operators, boolean operators, if-else statements, nested if, multiple condition testing, switch case, for loop, while loop, do-while loop, and use of break and continue. The document is intended as a reference for understanding basic programming structures in C.
● Introduction to Control Structures
Branching structures
● If statement, If-else statement, Nested if-else, else-if Ladder
● Switch statement
Looping Structures
● For loop, While loop, Do while loop
● break and continue
How to Setup Lunch in Odoo 18 - Odoo guidesCeline George
In Odoo 18, the Lunch application allows users a convenient way to order food and pay for their meal directly from the database. Lunch in Odoo 18 is a handy application designed to streamline and manage employee lunch orders within a company.
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...wygalkelceqg
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
More Related Content
Similar to Lesson 2 C STATEMENT IN PROGRAMMING (M).pdf (20)
The document discusses various control structures in C language that are used to control the flow of execution in a program. It explains the three types of execution flow as sequence, selection, and repetition. Under selection it covers if, if-else, if-else-if, switch statements. Under repetition it covers while, do-while, for loops. For each control structure, it provides syntax, examples and explanations.
The document discusses different types of selection and looping constructs in imperative programming languages. It describes if-else statements, switch-case statements, and how they allow a program to select different courses of action based on conditions. It also covers while, for, and do-while loops and how they repeatedly execute blocks of code while or until certain conditions are met. Examples are provided for each type of construct to illustrate their syntax and usage.
This document discusses various control structures in programming like if-else statements, switch statements, and loops. It provides syntax and examples of using if-else statements to execute code conditionally based on simple or nested conditions. Switch statements allow selecting between multiple code blocks based on a variable's value. Loops like for, while, and do-while loops are covered, which allow repetitive execution of code. The break and continue statements are also introduced to control loop flow. Examples are provided to demonstrate different control structures for problems like finding largest of numbers, checking positive/negative/zero, and character input validation.
This document discusses flow of control in C programming. It covers selection structures like if/else statements that allow a program to make decisions based on boolean expressions. It also covers repetition structures like loops. The key control structures are sequences, selection, and repetition. Selection structures include if/else and switch statements. If/else allows two alternative paths, while switch supports multiple comparisons. Logical and relational operators are used to construct boolean expressions that if/else and switch evaluate. Proper indentation and braces are important for nested conditional statements.
Decision Making Statements, Arrays, StringsPrabu U
The document discusses various decision making and looping statements in C programming language. It describes if, if-else, nested if, switch statements for decision making. It also covers while, for, do-while and nested loops for looping/iteration. Examples are provided for each statement to illustrate their syntax and usage. Arrays, functions, recursion and passing arrays to functions are also mentioned as topics to be covered.
The document discusses various control structures in C programming, including selection and repetition structures. It covers conditional statements like if, if-else, if-else-if, nested if, and switch statements. These allow altering the flow of execution based on certain conditions. The if statement and if-else statement are used for simple conditional execution, while if-else-if is used to check multiple conditions. Nested if allows if statements within other if statements. Finally, the switch statement provides another way to conditionally execute code based on different case options.
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlENGWAU TONNY
The document discusses different types of flow control in programming including sequential, selection, and repetition structures. It provides examples of if/else statements, nested ifs, if-else ladders, and the conditional operator. It also covers switch-case statements as an alternative for complex decisions. Finally, it poses challenges for readers to code decision-making structures using if/else and switch-case statements.
1. C programs consist of functions that perform specific tasks. The main() function is where program execution begins.
2. This example program prints "Welcome to C" by using functions like printf() to output text and getch() to pause the program.
3. The #include directives tell the compiler to include header files containing declarations for functions like printf() and clrscr() that are used in the program.
The document discusses various conditional control statements in C language including if, if-else, nested if, if-else-if, switch case statements. It provides the syntax and examples for each statement. Key conditional control statements covered are:
1) if statement - Executes code if a condition is true.
2) if-else statement - Executes one block of code if condition is true and another if false.
3) Nested if statements - if statements within other if statements allow multiple conditions to be checked.
4) if-else-if statement - Allows multiple alternative blocks to be executed depending on different conditions.
5) switch case statement - Allows efficient selection from multiple discrete choices
The document discusses various decision making statements in C programming language including if, if-else, if-else-ladder, nested if-else, switch-case, goto, break, continue statements. It provides examples and explanations of how each statement works. Key decision making statements covered are if, if-else for simple conditions, if-else-ladder for multiple conditions, switch-case for choices, and goto for unconditional branching.
3-Conditional-if-else-switch btech computer in c.pdfArkSingh7
This document discusses conditional statements and branching in programming. It explains how conditional statements like if-else and switch statements allow programs to execute different blocks of code depending on logical conditions. The if statement and if-else statement are used to check conditions and branch the execution accordingly. The switch statement provides an alternative way to write multiple conditional checks using case labels. Break statements are used to terminate the execution of a switch or loop.
The document provides information on C programming concepts including data types, operators, control structures, and loops. It includes code examples to demonstrate printf() and scanf() functions, if/else conditional statements, while and for loops. It also defines relational, logical, and ternary operators and explains the three basic control structures: sequence, selection, and iteration. Key concepts around while, do-while, for loops and switch/case statements are described.
The document discusses conditional statements and flow control in C programming. It explains if, if-else, nested if, and comparison operators. Examples are provided to illustrate if statements to check even/odd numbers, grades passed/failed, guessing a secret number, checking alphabet characters, and finding the maximum of three numbers. Nested if statements can check multiple conditions. Conditional statements allow programmers to execute code conditionally based on boolean expressions evaluating to true or false.
Chap7_b Control Statement Looping (3).pptxFakhriyArif
The document discusses control statements in C programming, specifically if, if-else, and if-else-if statements. It provides the syntax and examples of using these conditional statements to execute code based on expression evaluations. It also covers nested if statements, when else clauses are attached, and the importance of brackets. The document then discusses the switch statement, providing syntax and an example to print the name of a month based on a number input. It emphasizes the need for break statements to terminate each case.
The document discusses various control statements in C programming such as if, if-else, nested if, switch case, break, continue, and goto statements. It provides the syntax and examples of using each statement. Key control statements covered include:
- if statement which executes code if a condition is true
- if-else statement which allows executing one code block if a condition is true and another if it is false
- nested if statements which allow logical conditions to be checked within other if blocks
- switch case statement which allows a variable to be tested against multiple values and execute the corresponding code block
This document provides an overview of key concepts in C programming including algorithms, flowcharts, operations and variables, conditional statements like if-else, switch case, loops like for, while, do-while. It includes examples to demonstrate printf, scanf, arithmetic operators, boolean operators, if-else statements, nested if, multiple condition testing, switch case, for loop, while loop, do-while loop, and use of break and continue. The document is intended as a reference for understanding basic programming structures in C.
● Introduction to Control Structures
Branching structures
● If statement, If-else statement, Nested if-else, else-if Ladder
● Switch statement
Looping Structures
● For loop, While loop, Do while loop
● break and continue
How to Setup Lunch in Odoo 18 - Odoo guidesCeline George
In Odoo 18, the Lunch application allows users a convenient way to order food and pay for their meal directly from the database. Lunch in Odoo 18 is a handy application designed to streamline and manage employee lunch orders within a company.
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical...wygalkelceqg
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Active Surveillance For Localized Prostate Cancer A New Paradigm For Clinical Management 2nd Ed Klotz
Prottutponnomotittwa: A Quiz That Echoed the Pulse of Bengal
On the 31st of May, 2025, PRAGYA – The Official Quiz Club of UEM Kolkata – did not merely organize another quiz. It hosted an ode to Bengal — its people, its quirks, its politics, its art, its rebellion, its heritage. Titled Prottutponnomotittwa, the quiz stood as a metaphor for what Bengal truly is: sharp, intuitive, spontaneous, reflective. A cultural cosmos that thrives on instinct, memory, and emotion.
From the very first slide, it became clear — this wasn’t a quiz made to showcase difficulty or elitism. It was crafted with love — love for Bangla, for its past, present, and its ever-persistent contradictions.
The diversity of the answer list tells the real story of the quiz. The curation was not random. Each answer was a string on a veena of cultural resonance.
In the “Cultural Pairings” round, Anusheh Anadil and Arnob were placed not just as musicians, but as voices of a modern, cross-border Bangla. Their works, which blend baul, jazz, and urban folk, show how Bengal exists simultaneously in Dhaka and Shantiniketan.
The inclusion of Ritwik Chakraborty and Srijit Mukherjee (as a songwriter) showed how the quiz masters understood evolution. Bangla cinema isn’t frozen in the Ray-Ghatak past. It lives, argues, breaks molds — just like these men do.
From Kalyani Black Label to Radhunipagol Chal, consumer culture too had its place. One is liquid courage, the other culinary madness — both deeply Bengali.
The heart truly swelled when the answers touched upon Baidyanath Bhattacharya and Chandril. Both satirists, both sharp, both essential. It was not just about naming them — it was about understanding what different types of literature means in a Bengali context.
Titumir — the play about a peasant rebel who built his own bamboo fort and dared to challenge the British.
Krishnananda Agamvagisha — the mystical Tantric who shaped how we understand esoteric Bengali spiritualism.
Subhas Chandra Bose — the eternal enigma, the braveheart whose shadow looms large over Bengal’s political psyche.
Probashe Ghorkonna — a story lived by many Bengalis. The medinipur daughter, who made a wholesome family, not only in bengal, but across the borders. This answer wasn’t just information. It was emotion.
By the end, what lingered was not the scoreboard. It was a feeling.
The feeling of sitting in a room where Chalchitro meets Chabiwala, where Jamai Shosthi shares the stage with Gayatri Spivak, where Bhupen Hazarika sings with Hemanga Biswas, and where Alimuddin Road and Webskitters occupy the same mental map.
You don’t just remember questions from this quiz.
You remember how it made you feel.
You remember smiling at Keet Keet, nodding at Prabuddha Dasgupta, getting goosebumps at the mention of Bose, and tearing up quietly when someone got Radhunipagol Chal right.
This wasn’t a quiz.
This was an emotional ride of Bangaliyana.
This was — and will remain — Prottutponnomotittwa.
Search Engine Optimization (SEO) for Website SuccessMuneeb Rana
Unlock the essentials of Search Engine Optimization (SEO) with this concise, visually driven PowerPoint. Inside you’ll find:
✅ Clear definitions and core concepts of SEO
✅ A breakdown of On‑Page, Off‑Page, and Technical SEO
✅ Actionable best‑practice checklists for keyword research, content optimization, and link building
✅ A quick‑start toolkit featuring Google Analytics, Search Console, Ahrefs, SEMrush, and Moz
✅ Real‑world case study demonstrating a 70 % organic‑traffic lift
✅ Common challenges, algorithm updates, and tips for long‑term success
Whether you’re a digital‑marketing student, small‑business owner, or PR professional, this deck will help you boost visibility, build credibility, and drive sustainable traffic. Download, share, and start optimizing today!
This study describe how to write the Research Paper and its related issues. It also presents the major sections of Research Paper and various tools & techniques used for Polishing Research Paper
before final submission.
Finding a Right Journal and Publication Ethics are explain in brief.
How to Setup Renewal of Subscription in Odoo 18Celine George
A subscription is a recurring plan where you set a subscription period, such as weekly, monthly, or yearly. Based on this period, the subscription renews automatically. In Odoo 18, you have the flexibility to manage renewals either manually or automatically.
"Orthoptera: Grasshoppers, Crickets, and Katydids pptxArshad Shaikh
Orthoptera is an order of insects that includes grasshoppers, crickets, and katydids. Characterized by their powerful hind legs, Orthoptera are known for their impressive jumping ability. With diverse species, they inhabit various environments, playing important roles in ecosystems as herbivores and prey. Their sounds, often produced through stridulation, are distinctive features of many species.
Stewart Butler - OECD - How to design and deliver higher technical education ...EduSkills OECD
Stewart Butler, Labour Market Economist at the OECD presents at the webinar 'How to design and deliver higher technical education to develop in-demand skills' on 3 June 2025. You can check out the webinar recording via our website - https://oecdedutoday.com/webinars/ .
You can check out the Higher Technical Education in England report via this link 👉 - https://www.oecd.org/en/publications/higher-technical-education-in-england-united-kingdom_7c00dff7-en.html
You can check out the pathways to professions report here 👉 https://www.oecd.org/en/publications/pathways-to-professions_a81152f4-en.html
The PDF titled "Critical Thinking and Bias" by Jibi Moses aims to equip a diverse audience from South Sudan with the knowledge and skills necessary to identify and challenge biases and stereotypes. It focuses on developing critical thinking abilities and promoting inclusive attitudes to foster a more cohesive and just society. It defines bias as a tendency or prejudice affecting perception and interactions, categorizing it into conscious and unconscious (implicit) biases. The content highlights the impact of societal and cultural conditioning on these biases, particularly within the South Sudanese context.
How to Create Time Off Request in Odoo 18 Time OffCeline George
Odoo 18 provides an efficient way to manage employee leave through the Time Off module. Employees can easily submit requests, and managers can approve or reject them based on company policies.
♥☽✷♥
Make sure to catch our weekly updates. Updates are done Thursday to Fridays or its a holiday/event weekend.
Thanks again, Readers, Guest Students, and Loyalz/teams.
This profile is older. I started at the beginning of my HQ journey online. It was recommended by AI. AI was very selective but fits my ecourse style. I am media flexible depending on the course platform. More information below.
AI Overview:
“LDMMIA Reiki Yoga refers to a specific program of free online workshops focused on integrating Reiki energy healing techniques with yoga practices. These workshops are led by Leslie M. Moore, also known as LDMMIA, and are designed for all levels, from beginners to those seeking to review their practice. The sessions explore various themes like "Matrix," "Alice in Wonderland," and "Goddess," focusing on self-discovery, inner healing, and shifting personal realities.”
♥☽✷♥
“So Life Happens-Right? We travel on. Discovering, Exploring, and Learning...”
These Reiki Sessions are timeless and about Energy Healing / Energy Balancing.
A Shorter Summary below.
A 7th FREE WORKSHOP
REiki - Yoga
“Life Happens”
Intro Reflections
Thank you for attending our workshops. If you are new, do welcome. We have been building a base for advanced topics. Also, this info can be fused with any Japanese (JP) Healing, Wellness Plans / Other Reiki /and Yoga practices.
Power Awareness,
Our Defense.
Situations like Destiny Swapping even Evil Eyes are “stealing realities”. It’s causing your hard earned luck to switch out. Either way, it’s cancelling your reality all together. This maybe common recently over the last decade? I noticed it’s a sly easy move to make. Then, we are left wounded, suffering, accepting endless bad luck. It’s time to Power Up. This can be (very) private and quiet. However; building resources/EDU/self care for empowering is your business/your right. It’s a new found power we all can use for healing.
Stressin out-II
“Baby, Calm down, Calm Down.” - Song by Rema, Selena Gomez (Video Premiered Sep 7, 2022)
Within Virtual Work and VR Sims (Secondlife Metaverse) I love catching “Calm Down” On the radio streams. I love Selena first. Second, It’s such a catchy song with an island feel. This blends with both VR and working remotely.
Its also, a good affirmation or mantra to *Calm down* lol.
Something we reviewed in earlier Workshops.
I rarely mention love and relations but theres one caution.
When we date, almost marry an energy drainer/vampire partner; We enter doorways of no return. That person can psychic drain U during/after the relationship. They can also unleash their demons. Their dark energies (chi) can attach itself to you. It’s SYFI but common. Also, involving again, energy awareness. We are suppose to keep our love life sacred. But, Trust accidents do happen. The Energies can linger on. Also, Reiki can heal any breakup damage...
(See Pres for more info. Thx)
Based in Wauconda, Diana Enriquez teaches dual-language social studies at West Oak Middle School, guiding students in grades 6-8. With a degree from Illinois State University and an ESL/Bilingual certification, she champions diversity and equity in education. Diana’s early experience as a special education paraprofessional shaped her commitment to inclusive and engaging learning.
Christian education is an important element in forming moral values, ethical Behaviour and
promoting social unity, especially in diverse nations like in the Caribbean. This study examined
the impact of Christian education on the moral growth in the Caribbean, characterized by
significant Christian denomination, like the Orthodox, Catholic, Methodist, Lutheran and
Pentecostal. Acknowledging the historical and social intricacies in the Caribbean, this study
tends to understand the way in which Christian education mold ethical decision making, influence interpersonal relationships and promote communal values. These studies’ uses, qualitative and quantitative research method to conduct semi-structured interviews for twenty
(25) Church respondents which cut across different age groups and genders in the Caribbean. A
thematic analysis was utilized to identify recurring themes related to ethical Behaviour, communal values and moral development. The study analyses the three objectives of the study:
how Christian education Mold’s ethical Behaviour and enhance communal values, the role of
Christian educating in promoting ecumenism and the effect of Christian education on moral
development. Moreover, the findings show that Christian education serves as a fundamental role
for personal moral evaluation, instilling a well-structured moral value, promoting good
Behaviour and communal responsibility such as integrity, compassion, love and respect. However, the study also highlighted challenges including biases in Christian teachings, exclusivity and misconceptions about certain practices, which impede the actualization of
2. TABLE OF CONTENT
If statement
If else if statement
Nested If structure
COMPUTER FUNDAMENTAL & PROGRAMMING
Switch Case structure
If else statement
3. LEARNING OUTCOME
1
❖ Understand how to use logical expressions to control
program flow.
❖ Learn to write and interpret simple and nested if-else
statements.
❖ Develop an appreciation for code efficiency and
optimization when using control structures.
❖ Apply control statements to practical programming
scenarios.
❖ Understand how control structures are used in real-
world applications to control program behavior.
COMPUTER FUNDAMENTAL & PROGRAMMING
4. 2
Control structures allow to change the ordering of how the statements in a program is
executed
Control Structure
COMPUTER FUNDAMENTAL & PROGRAMMING
Types of control structures:
❖Decision control structures
allow to select specific sections of code to be executed
❖Repetition control structures
allow to execute specific sections of the code a number of times
5. 3
If else statement
COMPUTER FUNDAMENTAL & PROGRAMMING
C language statements that allows a programmer to select and execute specific
blocks of code while skipping other sections.
Include types such as:
• If-Else
• If-Else-If
• Switch structure
6. if – else Statement
4
COMPUTER FUNDAMENTAL & PROGRAMMING
"The if-else statement is used to
express decisions” -Dennis Ritchie.
In a simple if-else conditional statement,
there are two given choices the computer
could make.
However, the computer could only choose one
of them. It is like having two girlfriends, you
could only choose one to marry (if you are a
true Christian, not a fake one). The formal
syntax of if-else is:
if (condition)
statement;
else
statement;
7. Example
5
COMPUTER FUNDAMENTAL & PROGRAMMING
1. Write a program that determines if the input age
is qualified to vote or not. The qualifying age is 18
years old and above.
#include<stdio.h>
int main()
{
int age;
printf(“nEnter Age : ");
scanf("%i",&age);
if(age>=18)
printf("%i is Qualify age to vote",age);
else
printf("%i is NOT Qualify age to vote",age);
return 0;
}
8. Example
6
COMPUTER FUNDAMENTAL & PROGRAMMING
2. Write a program that determines if the input
number is POSITIVE or NEGATIVE. Consider 0 as
positive (considering that it contains no negative sign).
#include<stdio.h>
int main()
{
int number;
printf("n Enter number : ");
scanf("%i",&number);
if (number>=0)
printf("n %i is a Positive Number",number);
else
printf("n %i is a Positive Number",number);
return 0;
}
9. Example
7
COMPUTER FUNDAMENTAL & PROGRAMMING
3. Write program that will determine if the student is
passed or failed.
#include<stdio.h>
int main()
{
int grade;
printf("nn GRADE : ");
scanf("%i",&grade);
if(grade>=75)
printf("n ***** PASSED *****");
else
printf("n ***** FAILED *****");
return 0;
}
10. if Statement
8
COMPUTER FUNDAMENTAL & PROGRAMMING
if (condition)
statement;
if (condition)
statement;
if (condition)
statement;
if (condition)
statement
11. Example
9
COMPUTER FUNDAMENTAL & PROGRAMMING
#include <stdio.h>
int main()
{
int a;
printf("Enter number ");
scanf("%i",&a);
if (a==1)
printf("one");
if (a==2)
printf("TWO");
if (a==3)
printf("Three");
return 0;
}
12. if Compound
Statement
10
COMPUTER FUNDAMENTAL & PROGRAMMING
As in the if statement, compound statements may also be
used in if-else statements (provided they are grouped
together by braces).
if (expression)
{
statement1;
statement2;
…
}
else
{
statement3;
statement4;
…
}
If there is a need to
execute several statements
(compound statement),
then left and right {} braces
can group these
statements.
Syntax
13. 11
COMPUTER FUNDAMENTAL & PROGRAMMING
If there is a need to
execute several statements
(compound statement),
then left and right {} braces
can group these
statements.
Every time C language encounters an if statement,
1. It determines whether expression is true or false.
2. If expression is true, then C language executes
statement.
3. If expression is false, then C language ignores or skips
the remainder of the if statement and proceeds to
the next statement.
if Compound
Statement
14. if – else if Statement
12
COMPUTER FUNDAMENTAL & PROGRAMMING
user can decide among multiple options.
The if statements are executed from the
top down. As soon as one of the
conditions controlling the if is true, the
statement associated with that if is
executed, and the rest of the ladder is
bypassed. If none of the conditions is
true, then the final else statement will be
executed.
if (condition)
statement;
else if (condition)
statement; . .
else statement;
15. if structure
13
COMPUTER FUNDAMENTAL & PROGRAMMING
If there is a need to
execute several statements
(compound statement),
then left and right {} braces
can group these
statements.
if (condition)
{
statement1;
statement2;
…
}
else if (condition)
{
statement1;
statement2;
…
}
else
{
statement1;
statement2;
}
16. Example
14
COMPUTER FUNDAMENTAL & PROGRAMMING 2. Write a program that determines if the input number is
POSITIVE, NEGATIVE or ZERO.
#include <stdio.h>
int main() {
int number;
// Input a number from the user
printf("Enter a number: ");
scanf("%d", &number);
// Check and display if the number is positive, negative, or zero
if (number > 0)
{ printf(“%d”,number);
printf("The number is positive.n");
}
else if (number < 0)
{ printf(“%d”,number);
printf("The number is negative.n"); }
else {
printf(“%d”,number); printf("The number is zero.n");
}
return 0;
}
17. Example
15
COMPUTER FUNDAMENTAL & PROGRAMMING
3. Write program that will determine if the
student is passed or failed.
#include<stdio.h>
int main()
{
int n1,n2,choice;
float age;
printf("Enter Age : ");
scanf("%f",&age);
if(age<16)
{
printf("%.0f not Qualify",age);
}
else if((age>=16) && (age<=17))
{
printf(“You are %.0f, Eligible to vote for SK only",age);
}
else if((age>17) && (age<=25))
printf(“You are %.0f, Eligible to vote for SK & National",age);
else
printf("%.0f You are %.0f, Eligible to vote National only",age);
return 0;
}