10th Computer New Course Conditional Logic Unit-03
In 10th Class Computer New Course Conditional Logic, we will learn conditional statements, selection statements and solve programming exercises and objectives.
Q.1 Multiple choice questions.
- Conditional logic helps in ____________________.
a) decisions (Correct Answer)
2. ____________________ statements describe the sequence in which statements of the program should be executed.
c) control (Correct Answer)
3. In if statement, what happens if condition is false?
a) Program crashes
b) Indexes out of bound error
c) Further code executes (Correct Answer)
d) Compiler asks to change condition
int a =5;
Which of the following statement will execute?
a) a++ (Correct Answer)
c) both (a) and (b)
5. Which of the following is the condition to check a is a factor of c?
a) a%c==0 (Correct Answer)
6. A condition can be any ____________________ expression.
d) arithmetic, relational or logical (Correct Answer)
7. An if statement inside another if statement is called ____________________ structure.
a) nested (Correct Answer)
8. A set of multiple instructions enclosed in braces is called a ____________________.
c) block (Correct Answer)
Q.2 Define the following.
1) Control Statements
In order to solve a problem, there is a need to control the flow of execution of a program. Sometimes we need to execute one set of instructions if a particular condition is true and another set of instructions if the condition is false. Moreover we need to repeat a set of statements for a number of times. We can control the flow of program execution through control statements.
2) Selections Statements
The statements which help us to decide which statements should be executed next, on the basis of conditions, are called selection statements.
3) Sequential Control
Sequential control is the default control structure in C language. According to the sequential control, all the statements are executed in the given sequence.
A condition could be any valid expression including arithmetic expressions, relational expressions, logical expressions, or a combination of these.
5) Nested Selection Structures
Selection statement within selection statement are called nested selection structure.
Q.3 Briefly answer the following questions.
1) Why do we need selection statements?
Answer: Need of Selection Statements
Selection statements are needed where we need help to decide which statements should be executed next on the basis of some conditions.
2) Differentiate between sequential and selection statements.
Answer: Difference between Sequential and Selection Statements
In Sequential statements all the statements are executed in the given sequence, while in Selection statements the given condition decides which statement should be executed next.
3) Differentiate between if statement and if else statement with an example.
Answer: Differentiate between if statement and if else statement
In if statement, if the given condition returns true, then all the given statements gets executed followed by that if statement, and if the given condition returns false then nothing gets executed. While in if-else statement if the given condition returns true then all the statements gets executed followed by that if condition and if the given condition returns false then all the statements followed by the else part gets executed.
4) What is the use of nested selection structure?
Answer: Use of Nested Selection Structure
Selection statements within selection statements are called nested selection structure. The use of nested selection structure is that inside if block or inside an else block, we can have other if statements or if-else statements. It also means that inside those inner if statements or if-else statements we can have even more if statements or if-else statements and so on.
5) Write the structure of if statement with brief description.
Answer: Structure of if-statement
C language provides if statement in which we specify a condition, and associate a code to it. The code gets executed if the specified condition turns out to be true, otherwise the code does not get executed.
Structure of if statement
if statement has the following structure in C language:
Here is a brief description of different components involved in the general structure.
- In the given structure, if is a keyword that is followed by a condition inside parenthesis ()
- A condition could be valid expression including arithmetic expressions, relational expressions, logical expressions or a combination of these. Here are few examples of valid expressions that can be used as condition.
10th Class Computer Unit-05: Functions
10th Class Computer New Course Data & Repetition Unit-04
10th Class Computer New Course User Interaction Unit-02
10th Class Computer New Course ITP Unit-01
9th Computer New Course Designing Website Unit-05
9th Computer New Course Data and Privacy Unit-04
9th Computer New Course Networks Unit-03
9th Computer New Course Binary System Unit-02
9th Computer New Course Problem Solving Unit-01
Buy Best Stationery Products in Pakistan
Piano Ballpoint Pen
ORO Trimetal Pencil
Dollar Clipper Pen
UHU 10×7 ml Pack of 10 PCs
Glue Stick 8g Pack Of 12 PCs
Color Pencils Box of 12 PCs
For more stationery items please visit : https://stationerystore.pk