Header Ads Widget

Responsive Advertisement

Control Structure

Control Structure are fundamental concepts that are used to control the flow of execution of a program.
It enable a program to make decisions based on certain conditions and to repeat code until certain conditions are met.

There are two type of control Structure:

1) Conditional Statement: it allows us to test a condition and execute a certain codes only if it satisfies the condition. It helps computer to take decision on base of condition, making the program more flexible and powerful. The most commonly use conditional statements are:

1-If:it is used to test a condition and execute code only if condition is true!!

2-If else: it is used to test a condition and execute one of the code if condition is true!! And If condition is false it execute other block of code.

3- else if: it is used to test multiple conditions and execute one of the code if condition is true!! And If condition is false it execute other block of code.



2) Loops: it allows perticular block of code to run multiple times untill the given condition is satisfied.

For loops: its used to iterate over a sequence of values, such as a list or a range of numbers.
Syntax: for variable in sequence 
" Code to execute for each value"
When to use loop statement:-
Incrementing: it involves adding a fixed value to a variable with each iteration of loop. This is often use in counting loops. Where a variable is incremented until it reaches a certain value.
Example: for i in range(1,6):
Print (i)

Accumulatiing loop: it's used to calculate a sum of other accumulated value this done by adding each value to the previous total.
Example: total = 0
For i in range(1,6)
Total i+1


Repeat until loops: this is used to execute a block of code atleast once and then continue executing it untill the 

Post a Comment

0 Comments