📖 Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 94question

Solving · Part 4

Chapter 2: Chapter 2 · Computer Science

value, but farmer also has the same value as they. In line ( ), goat and wolf have the same value, but farmer also has the same value as they. Thus, the sequence has achieved the goal state, without violating the constraints. .

. Alternative statement A condition is a phrase that describes a test of the state. If C is a condition and both S1 and S2 are statements, then if C S1 else S2 is a statement, called an alternative statement, that describes the following action: . Test whether C is true or false.

. If C is true, then do S1; otherwise do S2. In pseudo code, the two alternatives S1 and S2 are indicated by indenting them from the keywords if and else, respectively. Alternative control flow is depicted in the flowchart of Figure .

. Condition C has two outgoing arrows, labeled true and false. The true arrow points to the S1 box. The false arrow points to the S2 box.

Out going arrows of S1 and S2 point to the same box, the box after the alternative statement. C S1 true false S2 Figure . : Alternative control flow Chapter Page - - Conditional statement: Sometimes we need to execute a statement only if a condition is true and do nothing if the condition is false. This is equivalent to the alternative statement in which the else- clause is empty.

This variant of alternative statement is called a conditional statement. If C is a condition and S is a statement, then if C S is a statement, called a conditional statement, that describes the following action: . Test whether C is true or false. .

If C is true then do S; otherwise do nothing. The conditional control flow is depicted in the flowchart of Figure . . C S true false Figure .

: Conditional control flow Example . . Minimum of two numbers: Given two numbers a and b, we want to find the minimum of the two using the alternative statement. Let us store the minimum in a variable named result.

Related topics

Have a question about this topic?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →