Professional Documents
Culture Documents
CH 01
CH 01
1. What are the different types of control structures? Define each type.
Control structures: Control structures are used in programming to control the flow of
execution. They determine how different parts of a program are executed based on certain
conditions. Here are three common types of control structures:
a. Sequence: It represents a set of instructions executed in a specific order, one after
another.
b. Selection: It allows the program to make decisions and choose between different paths
based on certain conditions. Common selection structures include if statements and switch
statements.
c. Iteration (or loop): It enables the program to repeat a certain block of code multiple times
until a specific condition is met. Common iteration structures include for loops, while loops,
and do-while loops.
Relational operators: Relational operators are used to compare values and determine the
relationship between them. Here are the common relational operators:
a. Equal to (==): Checks if two values are equal.
b. Not equal to (!=): Checks if two values are not equal.
c. Greater than (>): Checks if the value on the left is greater than the value on the right.
d. Less than (<): Checks if the value on the left is less than the value on the right.
e. Greater than or equal to (>=): Checks if the value on the left is greater than or equal to the
value on the right.
f. Less than or equal to (<=): Checks if the value on the left is less than or equal to the value on
the right.
Logical operators: Logical operators are used to combine or modify logical conditions in
programming. They work with Boolean values (true or false). Here are the common logical
operators:
a. AND (&&): Returns true if both conditions on either side of the operator are true.
b. OR (||): Returns true if at least one of the conditions on either side of the operator is true.
c. NOT (!): Negates the logical value of a condition. If a condition is true, applying the NOT
operator makes it false, and vice versa.
4. What are the differences between "AND" and "OR" operators? Give examples.
Q2. Create a program in Minecraft which assigns a number to a variable. Then display if the number
is even or odd.
Program to check if a number is even or odd:
# Assign a number to the variable
number = 12
Q3. Create a program in Minecraft which assigns a number to a variable. Find out if the number is
divisible by 3. If divisible by 3, multiply it by 10 and display the output.
Program to check if a number is divisible by 3 and multiply it by 10 if true: # Assign a
number to the variable
number = 27