Skip to main content

ads1

Class 10th Chapter :- 14 Loop Control Structures

  Loop Control Structures

 

All programming languages offers loop control structure (also known as looping) allowing programmers to execute a statement or group of statements multiple times.

In looping, the sequences of statements are executed until some exit condition is satisfied. The looping construct is composed of two parts: body of loop and control statement.

In entry controlled loop the exit/control condition is checked before executions of statements inside loop body.
In exit controlled loop the exit/control condition is checked after executions of loop body.
This means that in case of exit controlled loop, body will be executed at least once before exiting from the loop.4

for
while
do...while

The For Loop

The for loop is normally used when we want to execute block of statements fixed number of times. To make for loop more dynamic, we can use the exit condition inside for loop.

Syntax of For Loop for ( expression1; expression2; expression3)

The header of for loop contains three expressions separated by semicolons in parenthesis. All these expressions are optional. Statement-block which is also known as body of for loop may contain simple statement or compound statement.

The While Loop

When number of iteration cannot be pre-determined and when loop terminating condition is to be tested before entering the loop, at that time use of while loop is more suitable.

The do-while loop

While loop, the test expression is checked before executing body of loop. The do...while loop should be used when the test expression is to be checked after executing body of loop. As we are checking test condition at the end of loop, the do...while loop is a kind of exit-controlled loop.   

The Infinite Loop Any loop in a program becomes infinite loop if it runs forever and program control never comes out of it. The loop becomes infinite due to non availability of exit condition in the logic of loop.

int main ()
for(;;)
printf(" This for loop will run forever..... \n");

Choose the correct option from the following:

(1) How many times printf statement is executed in the following program segment ?
int num1 = 3, num2 = 6;
while(numl < num2) {
printf(" Hello Students...");
num1 = numl + 1;
(a) 1
(b) 2
(c) 3
(d) 6

(2) What is the output of following program segment ?
int a = 5, b = 10;
do
a = a + 1;
}while( a < = b); printf(" %d", a);

(a) 10
(b) 9
(c) 11
(d) 15

(3) What is the output of following program segment ?
int main(){
int i;
for(i = 0; i < 10; i++);
printf("%d", i);

(a) 0123456789
(b) 9
(c) 10
(d) Error

(4) What is the value of a number variable after execution of following code ?
int number = 1; while(number <5){
number = number + 1; if( number = = 3) {
continue;
(a) 1
(b) 3
(c) 5
(d) None of these



    

ads2

Popular posts from this blog

11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following:

    11. Write a Java program to input basic salary of an employee and calculate its Gross salary according to following: Basic Salary <= 10000 : HRA = 20%, DA = 80% Basic Salary <= 20000 : HRA = 25%, DA = 90% Basic Salary > 20000 : HRA = 30%, DA = 95% Static Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     if(basic <=10000)     {         da = basic * 0.8;         hra = basic *0.2;     }              else if(basic <=20000)     {         da = basic * 0.9;         hra = basic *0.25;     }     else     {         da = basic * 0.95;         hra = basic * 0.3;     }     gross = basic + da + hra;     System.out.println("The Gross Salary is :-"+gross);     } } Output :-  Dynamic Solution :-  class salary {     public static void main(String args[])     {     double basic=20000.50,gross,da,hra;     Scanner in = new Scanner(System.in);     System.out.println("Enter the Basic Salary

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise or class wise.

1. Given the school result data, analyses the performance of the students on #different parameters, e.g subject wise  or class wise. Solution :-   # x-axis is shows the subject and y -axis # shows the markers in each subject # import pandas and matplotlib  import pandas as pd  import matplotlib.pyplot as plt # Simple Line Chart with setting of Label of X and Y axis, # title for chart line and color of line  subject = ['Physic','Chemistry','Mathematics', 'Biology','Computer'] marks =[80,75,70,78,82] # To draw line in red colour plt.plot(subject,marks,'r',marker ='*')     # To Write Title of the Line Chart plt.title('Marks Scored') # To Put Label At Y Axis plt.xlabel('SUBJECT')           # To Put Label At X Axis plt.ylabel('MARKS')             plt.show() Output :- 

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category.

24.Create a Data Frame quarterly sales where each row contains the item category, item name, and expenditure. Group the rows by the category and print the total expenditure per category. import pandas as pd  # initialize list of lists data = [['CAR','Maruti',1000000],['AC','Hitachi',55000],['AIRCOLLER','Bajaj',12000], ['WASHING MACHINE','LG',15000],['CAR','Ford',7000000],['AC','SAMSUNG',45000],['AIRCOLLER','Symphony',20000],['WASHING MACHINE','Wirlpool',25000]] Col=['itemcat','itemname','expenditure'] # Create the pandas DataFrame qrtsales = pd.DataFrame(data,columns=Col) # print dataframe.  print (qrtsales) qs=qrtsales.groupby('itemcat')  print('Result after Filtering Dataframe')  print(qs['itemcat','expenditure'].sum()) Output :-