Conditional statement ss1


Published on

Published in: Technology, Business
1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Conditional statement ss1

  1. 1. Conditional Statement<br />
  2. 2. Conditional Statements<br />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.<br />
  4. 4. IF-THEN STATEMENT<br />It specifies that a certain statement will be executed only if the expression is true<br />
  5. 5. SYNTAX<br />IF condition THEN expression<br />
  6. 6. Example<br />IF the telephone is ringing THEN<br />answer the telephone<br />
  7. 7. RELATIONAL OPERATIONS<br />=<br />><br /><<br />>=<br /><=<br />
  8. 8. SAMPLE PROBLEMS<br />
  9. 9. Write a program that will output “Congratulations!” if the student’s grade is greater than or equal 75.<br />
  10. 10. Rem<br />Clear<br />Input G<br />IF G>=75 THEN Print “Congratulations!”<br />End<br />
  11. 11. 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.<br />
  12. 12. Clear<br />Input P<br />If P>1000 THEN d=P*.1<br />Print d<br />End<br />
  13. 13. IF-THEN-ELSE Statement <br />It allows the computer to choose one of the given two alternatives. <br />
  14. 14. SYNTAX<br />IF condition THEN expression1 ELSE expression2<br />
  15. 15. SAMPLE PROBLEMS<br />
  16. 16. 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<br />
  17. 17. REM<br />Clear<br />Input x,y<br />If x>y THEN S=x+y: Print S<br />ELSE<br />D=x-y : Print D<br />End<br />
  18. 18. 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.<br />
  19. 19. REM<br />Clear<br />Input A<br />If A>=18 THEN Print “Qualified to vote!”<br />ELSE Print “Too Young!”<br />End<br />
  20. 20. NESTED IF or LADDERIZED IF-THEN-ELSE Statement<br />is used if there are three or more possible conditions and outcomes to be executed.<br />
  21. 21. SYNTAX<br />IF condition1 THEN<br />Expression1<br />ELSE IF condition2 THEN<br />Expression N<br />ELSE<br />Expression<br />
  22. 22. SAMPLE PROBLEMS<br />
  23. 23. 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.<br />
  24. 24. REM<br />Clear<br />Input x<br />IF x=b THEN Print “Blue”<br />ELSE IF x=r THEN Print “Red”<br />ELSE IF x=g THEN Print “Green”<br />ELSE IF x=y THEN Print “Yellow”<br />ELSE Print “Unknown Color!”<br />
  25. 25. ASSIGNMENT<br />
  26. 26. 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:<br />Year-Entry Number High School Level<br /> 1 Freshmen<br /> 2 Sophomore<br /> 3 Junior<br /> 4 Senior<br /> Other Entry No. Out-of-School<br />
  27. 27. Write a program that examine the value of a variable called temp. then display the following messages depending on the value assigned to the temp.<br />Temperature Message<br /> Less than 0 ICE<br />Between 0 and 100 Water<br /> Exceeds 100 STEAM<br />
  28. 28. T. O. L.<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.