SlideShare uma empresa Scribd logo
1 de 22
Conditional Statement
Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.
TYPES IF-THEN STATEMENT IF-THEN-ELSE STATEMENT LADDERIZED IF-THEN-ELSE STATEMENT
IF-THEN STATEMENT It specifies that a certain statement will be executed only if the expression is true
SYNTAX IF condition THEN expression
Example IF the telephone is ringing THEN answer the telephone
RELATIONAL OPERATIONS = > < >= <=
SAMPLE PROBLEMS
Write a program that will output “Congratulations!” if the student’s grade is greater than or equal 75.
Write a program that will ask for a price. If the price is greater than 1000, compute a 10% discount from the original price. Display the computed discount.
IF-THEN-ELSE Statement  It allows the computer to choose one of the given two alternatives.
SYNTAX IF condition THEN expression1 ELSE expression2
SAMPLE PROBLEMS
Write a program to print for the sum of two numbers if the first no. is greater than the second no., otherwise print their difference
Write a program that determines if the input age is qualified to vote or not. If qualified, displays “Qualified to Vote!” if not displays “Too Young!” We know that a qualifying age is 18 yrs. old and above.
NESTED IF or LADDERIZED IF-THEN-ELSE Statement is used if there are three or more possible conditions and outcomes to be executed.
SYNTAX IF condition1 THEN Expression1 ELSE IF condition2 THEN Expression N ELSE Expression
SAMPLE PROBLEMS
Write a program that displays an equivalent color once an input letter matches its first character for example b is for blue, r for red and so on. Here is the given criteria.
ASSIGNMENT
Write a program to display the high school level of a student, based on its year entry number for example the year-entry 1 means the student is a freshmen, 2 for sophomore, and so on. Here are the given criteria: Year-Entry Number	High School Level             1			    Freshmen          2		    Sophomore          3			       Junior          4			       Senior    Other Entry No.	  Out-of-School
2. Write a program that examines the value of a variable called temp. then display the following messages depending on the value assigned to the temp. Temperature			Message  Less than 0			   ICE Between 0 and 100	 Water    Exceeds 100			STEAM

Mais conteúdo relacionado

Mais de Jordan Delacruz (19)

Novel analysis
Novel analysisNovel analysis
Novel analysis
 
Motion tween resize
Motion tween resizeMotion tween resize
Motion tween resize
 
Computer motion tween
Computer motion tweenComputer motion tween
Computer motion tween
 
Introduction to layers
Introduction to layersIntroduction to layers
Introduction to layers
 
Graphics
GraphicsGraphics
Graphics
 
(Sept.14)
(Sept.14)(Sept.14)
(Sept.14)
 
(Sept.7)
(Sept.7)(Sept.7)
(Sept.7)
 
(Sept.5)
(Sept.5)(Sept.5)
(Sept.5)
 
(Sept. 8)
(Sept. 8)(Sept. 8)
(Sept. 8)
 
(Sept6. )
(Sept6. )(Sept6. )
(Sept6. )
 
(Sept15.)demo
(Sept15.)demo(Sept15.)demo
(Sept15.)demo
 
(Aug.31) introduction to macflash
(Aug.31) introduction to macflash(Aug.31) introduction to macflash
(Aug.31) introduction to macflash
 
(Sept.1) environment
(Sept.1) environment(Sept.1) environment
(Sept.1) environment
 
Introduction to basic programming repetition
Introduction to basic programming repetitionIntroduction to basic programming repetition
Introduction to basic programming repetition
 
Introduction to basic programming
Introduction to basic programmingIntroduction to basic programming
Introduction to basic programming
 
Algorithm and flowchart2010
Algorithm and flowchart2010Algorithm and flowchart2010
Algorithm and flowchart2010
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 
Arithmetic operator
Arithmetic operatorArithmetic operator
Arithmetic operator
 

Último

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 

Último (20)

psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 

Conditional statement ss2

  • 2. Conditional Statements Are statements that check an expression then may or may not execute a statement or group of statement depending on the result of the condition.
  • 3. TYPES IF-THEN STATEMENT IF-THEN-ELSE STATEMENT LADDERIZED IF-THEN-ELSE STATEMENT
  • 4. IF-THEN STATEMENT It specifies that a certain statement will be executed only if the expression is true
  • 5. SYNTAX IF condition THEN expression
  • 6. Example IF the telephone is ringing THEN answer the telephone
  • 9. Write a program that will output “Congratulations!” if the student’s grade is greater than or equal 75.
  • 10. Write a program that will ask for a price. If the price is greater than 1000, compute a 10% discount from the original price. Display the computed discount.
  • 11. IF-THEN-ELSE Statement It allows the computer to choose one of the given two alternatives.
  • 12. SYNTAX IF condition THEN expression1 ELSE expression2
  • 14. Write a program to print for the sum of two numbers if the first no. is greater than the second no., otherwise print their difference
  • 15. Write a program that determines if the input age is qualified to vote or not. If qualified, displays “Qualified to Vote!” if not displays “Too Young!” We know that a qualifying age is 18 yrs. old and above.
  • 16. NESTED IF or LADDERIZED IF-THEN-ELSE Statement is used if there are three or more possible conditions and outcomes to be executed.
  • 17. SYNTAX IF condition1 THEN Expression1 ELSE IF condition2 THEN Expression N ELSE Expression
  • 19. Write a program that displays an equivalent color once an input letter matches its first character for example b is for blue, r for red and so on. Here is the given criteria.
  • 21. Write a program to display the high school level of a student, based on its year entry number for example the year-entry 1 means the student is a freshmen, 2 for sophomore, and so on. Here are the given criteria: Year-Entry Number High School Level 1 Freshmen 2 Sophomore 3 Junior 4 Senior Other Entry No. Out-of-School
  • 22. 2. Write a program that examines the value of a variable called temp. then display the following messages depending on the value assigned to the temp. Temperature Message Less than 0 ICE Between 0 and 100 Water Exceeds 100 STEAM