Computer Science, asked by nishanth49, 11 months ago

About loop and explain about different types of loops

Answers

Answered by parkerh965
4

looping is mechanism in programming which allows repeatation of task .. like example :- i want to names of 20 students so instead of writing 20 statements to ask name i can simply create an array of 20 elements and loop over 20 times and every time through loop i can ask name of student and store in array index of cuurent loop time..

types of loops are:

for loop,while loop,do while loop:

For Loop:

for loop is used to iterate specified amount of time without having to create a breaking mechanism when our task is done. Its syntax in c is like

For(intialization statement;test statement; increament/drecrement)

example :counting to 10 is for(i=1;i<=10;i++)

While loop:

while loop is used when we are not sure about how many steps it will take to perform a certain calculation. in while loop we creating breaking mechanism by defining a certain condition which when met will break out of the loop continue to rest of the programs. syntax of while loop in c is

While(condition){

}

example: counting 10

i = 1

while(i<=10){

i++

}


Do-While Loop:

do while loop is used when we want a loop to execute at least one.condition is given at end to loop where it will check condition, if it evalutes to true it will loop otherwise it will break the loop. syntax in c is

do{

}while(condition);


Similar questions