You are on page 1of 3

DELA CRUZ, ART EZENIEL M.

ICT - 107

LOGPROG

1. What are the different control structures? (3) Briefly explain each, and give an
example on how each control structure is used.

• Sequential control structure. These the line-by-line execution by which


statements are executed sequentially, in the same order in which they
appear in the program. They might, for example, carry out a series of
read or write operations, arithmetic operations, or assignments to
variables.

• Selection control structure. The selection control structure allows one


set of statements to be executed if a condition is true and another set
of actions to be executed if a condition is false. Examples are the if-elif-
else structures.

• Iteration control structure. a statement or block is executed until the


program reaches a certain state, or operations have been applied to
every element of a collection. This is usually expressed with keywords
such as while , repeat , for , or do.. until

2. When do we use boolean variables? Give a specific programming problem where


we need to use boolean variables.

• Boolean variable is used when a programmer programmed a program a


“true” or “false” based logical structure. This only means that there are
two statements that needed to be determined if either/neither true or
false by using logical operators
• Programming problem where we need to use Boolean variable:
o if x==5 or y<=6

3. What is the difference between a boolean variable and a boolean expression?

• A Boolean variables are variables that can have only two possible
values: true, and false, while a Boolean expression is a logical statement
(that uses 2 Boolean variable) that is either TRUE or FALSE.

3. Briefly discuss the following flowchart symbols:


Named as “TERMINAL”
The terminator symbol marks the starting or
ending point of the system. It usually contains the
word "Start" or "End."
Named as “DECISION”
A decision or branching point. Lines representing
different decisions emerge from different points of
the diamond.
Action or Process Symbol
A box can represent a single step ("add two cups of
flour"), or an entire sub-process ("make bread")
within a larger process.
Input/Output Symbol
Represents material or information entering or
leaving the system, such as customer order (input)
or a product (output).

4. What are the 2 different loops we’ve discussed so far? Give an example on when
they’re used, and the differences of the two.
• while loop – a condition-controlled loop. In order for a loop to stop
executing, something has to happen inside the loop to make the
condition is false (example: while z = < 10: z = z + 5 print (z))
• for loop – a count-controlled loop. by using range or list, it continuously
repeats the argument until the number of range or list is done.

5. What are the advantages of using a loop structure?


• It provides code re-usability. Using loops, we do not need to write the
same code again and again. Using loops, we can traverse over the
elements of data structures.
6. Create a script that repeatedly asks for an input from the user and store it in the
variable next_num, and add it to a variable named accumulator. If next_num is -1,
exit the loop and print the accumulator variable. Which part of the code is the
condition clause? Which is/are the statement/s?

accumulator = 0

next_num = int(input("Input any integer"))


while next_num != -1:

accumulator = accumulator + next_num

next_num = int(input("Input any integer"))

print (accumulator)

7. Use the range function to create an iterable of even numbers between 1 and
1337.
for num in range (2, 1337, 2):
print (num)

You might also like