Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In your own words, describe the difference between an \"if-statement\" and an

ID: 3648710 • Letter: 1

Question

1. In your own words, describe the difference between an "if-statement" and an "if-then-else" statement.

2. Come up with one new situation (i.e. not already mentioned by your classmates), of a situation drawn from real life, where you would use an if-statement, and one where you would use and if-then-else statement.

Explanation / Answer

answer: Normally, your program flows along line by line in the order in which it appears in your source code. The if statement enables you to test for a condition (such as whether two variables are equal) and branch to different parts of your code, depending on the result. The simplest form of an if statement is this: if (expression) statement; The expression in the parentheses can be any expression at all, but it usually contains one of the relational expressions. If the expression has the value 0, it is considered false, and the statement is skipped. If it has any nonzero value, it is considered true, and the statement is executed. Consider the following example: if (bigNumber > smallNumber) bigNumber = smallNumber; for different conditions we use if then else statement. The simplest form of an 'if - then' construct expressed in C is as follows. If (x == 10) DoSomething(x); If an if - then type construct has more than one statement to execute C uses curly braces to enclose the statements as follows... If (x > 10) { DoFirstThing; DoSecondThing; }