Control Structures are just a method of describing the flow of control in a program. If self-contained modules known as logic or control structures are used, any algorithm or program may be made more transparent and understandable. It simply examines and decides which way a program should run based on a set of factors or […]
To start, you canControl Structures are just a method of describing the flow of control in a program. If self-contained modules known as logic or control structures are used, any algorithm or program may be made more transparent and understandable. It simply examines and decides which way a program should run based on a set of factors or situations. There are three fundamental forms of logic or control flow, to consider: Sequence logic, often known as sequential flow, is a type of logic that follows a set Selection logic, also known as conditional flow, is a type of logic that allows you to make iteration logic, often known as repeating flow, is a type of logic that repeats itself.
Sequential
sequential statements are a set of statements whose execution process happens In a sequence. The problem with sequential statements is that if the logic has broken in any one of the lines, then the complete source code execution will break default mode. Sequential execution of code statements like following a recipe.
code:
In the code, this is a sequential statement
a=20 b=10 c=a-b print(“Subtraction is : “,C)
1.Selection/Decision control statements
In Python, the selection statements are also known as Decision control statements or branching statements. The selection statement allows a program to test several conditions and execute instructions based on which condition Is true.
Some Decision Control Statements are
Simple if: If statements are the control flow statement that helps us to run a particular code, but only when a certain condition is met or satisfied. A simple has only to check one of the condition.
code example:n = int (input() )if n % 2 == 0:
print(“n is an even number”, n)
if-else: The if-else statement evaluates the condition and will execute the body of if if the test condition is True. But if the condition is False, then the body of else is executed
examble: n = int(input ())if n% 2 == 0:
print(“n is even”,n) else: print(“n is odd”, n)
nested it: Nested if statements are if statements are present in another Is Statements
examble: x =30 y= 5 z= 56 if x > y : if x > z
print(“x value is big”) else: print(“z value is big”)
elif y> z: print(“y value is big”) else: print (“z is big”)
if test condition:
If statement(S): else: else1 statement(s):
else: else statement(s): Repetition
A renetition statement is used for repeat a group of programming instructions.
In Python, we generally have two loops statements:
• while loop
for loon: A for loop is used to iterate over a sequence that is either a list. Tuple, dictionary or a set. We can execute a set or statements once for each Item in a list tuple, or dictionary.
Ist = [1, 2, 3, 4, 5] for i in range(len(Ist)):
print(Ist[i], end = “‘”) for j in range (0,10):
print(j, end = ‘’ ‘’)
while loop: In Python, while loops is used to execute a block of statements repeatedly until a given condition is true. Then, the expression is checked again and, if it is still true, the bod is executed again. This continues until the expression becomes false.
example: m= 6 i= 0 while i<m print(I,end=” ‘’)
¡=i+ 1 print(“End”)
sequential execution or sequential flow:
The arithmetic comparison operators in C++ work much like the symbols we use in mathematics. Each of these operators returns a true or a false
x<= y// x is less than or equal to y
x>y x IS greater than y
x>= y//x is greater than or equal to y
x < y// x is less than y x == y// x Is equal to y
x! = y//x is not equal to
We also have Boolean operators for combining expressions.
Again, these operators return true or false
!x //the NOT operator (negation) — true IF x is false.
X && Y // the AND operator — true if both x and y are true
x Ily // the OR operator — true if either x or y (or both) are true.
These operators will be commonly used as test expressions In selection statements or repetition statements (loops).
Work Cited
dann, wanda p, & push, randy. (n.d.). learning to program with Alice, 3rd edition.
Select your paper details and see how much our professional writing services will cost.
Our custom human-written papers from top essay writers are always free from plagiarism.
Your data and payment info stay secured every time you get our help from an essay writer.
Your money is safe with us. If your plans change, you can get it sent back to your card.
We offer more than just hand-crafted papers customized for you. Here are more of our greatest perks.