Se está descargando tu SlideShare. ×

# Conditional statement

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Próximo SlideShare
Selection statements
Cargando en…3
×

1 de 20 Anuncio

# Conditional statement

Conditional statement

Conditional statement

Anuncio
Anuncio

Anuncio

Anuncio

### Conditional statement

1. 1. Conditional Statement Presented by: Maximino E. Santos Jr. Computer Teacher
2. 2. Conditional Statement Conditional statement are statements that check an expression then may or may not execute a statement or group of statements depending on the result of the condition.
3. 3. The IF statement The general form of the if statement is: if (expression) statement; where: if is a reserve word in Turbo C expression is relational or boolean expression that evaluates to a TRUE (1) or FALSE (0) value statement may either be a single Turbo C statement or a block of Turbo C statements.
4. 4. The IF statement The general form of the if statement with block of statements is: if (expression) { statement_sequence; } In an if statement, if the expression evaluates to TRUE(1), the statement or the block statements that forms the target of the if statement will be executed. Otherwise, the program will ignore the statement or the block of statements.
5. 5. The IF statement Note: Never place a semicolon after the expression in an if statement.
6. 6. Example 1 Write a program that will output “Congratulations you PASSED!” if the student’s grade is greater than or equal to 60.
7. 7. Example 2 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.
8. 8. The IF-ELSE statement The general form of the if-else statement is: if (expression) statement_1; else statement_2;
9. 9. The IF-ELSE statement where: if is a reserve word in Turbo C expression is relational or boolean expression that evaluates to a TRUE (1) or FALSE (0) value statement_1 and statement_2 may either be a single Turbo C statement or a block of Turbo C statements.
10. 10. The IF-ELSE statement The general form of the if-else statement with block of statements is: if (expression) { statement_sequence; } else { statement_sequence; }
11. 11. The IF-ELSE statement If an if-else statement, if the expression is TRUE (1), the statement or block of statements after the if statement will be executed; otherwise, the statement or block of statements in the else statement will be executed.
12. 12. The IF-ELSE statement Note: Only the code associated with the if or the code that is associated with the else executes, never both.
13. 13. Example 3 Write a program that will output “Congratulations you PASSED!” if the student’s grade is greater than or equal to 60. Otherwise output, “Sorry you FAILED!”
14. 14. Fin