O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

LOOPING IN C- PROGRAMMING.pptx

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Próximos SlideShares
ComputerSoftware.pdf
ComputerSoftware.pdf
Carregando em…3
×

Confira estes a seguir

1 de 16 Anúncio

Mais Conteúdo rRelacionado

Mais recentes (20)

Anúncio

LOOPING IN C- PROGRAMMING.pptx

  1. 1. { LOOPING IN C- PROGRAMMING PRESENTED BY : AFANJI PHILL MUKETE BUWAGA RYAN ARREY NWANKO FORGIVE FUHNWIE HILLSON NGWASIRI BALALA OLIVIER
  2. 2. At the end this presentation, you should be able to:  Define a looping as concern C-programming  Why we loop in C-programming  Advantages of looping  Types of C loops  Essential components of a loop  Discuss on While loop and examples  Discuss on Do loop and examples  Discuss on the For loop and examples  Draw flowchart for the various types of looping in C-programming OUTLINE
  3. 3.  The looping can be defined as repeating the same process multiple times until a specific condition Satisfies or is true. The sequence of statements to be executed is kept inside the curly bracket { }known as loop body , condition is verified, and if it is found to be true the loop body is executed again. And when the condition check false, the loop body is not executed WHAT IS LOOPING IN C- PROGRAMMING?
  4. 4.  Looping simplifies the complex problems into the easy ones.  Looping enables to alter the flow of the program so that instead of writing the same code again and again, we can execute the same code for a finite number of times.  For example, if we need to print “UNIVERSITY OF FOMIC POLYTECHNIC” 15-times then, we can use the Printf once inside a loop which runs up to 15 iterations. Why we loop in C-Programming ?
  5. 5.  It provides codes reusability.  Using loops we do not need to write the same code again and again.  Using loops, we can access each elements stored in the array so that the data can be checked or used as part of the process. data structure (array is a series of memory location which holds a single item of data). Advantages of looping in C- Programming
  6. 6. There are three types of loops in C language those are given below;  While  Do while  For Types of C Loops
  7. 7.  Counter  Initialization of the counter with initial value  Condition to check with the optimum value of the counter  Statement(s) to be executed by iteration  Increment/decrement Essential components of a loop
  8. 8.  Thewhileloopincistobeusedinthescenariowhere theblockofstatementsisexecutedinthewhileloopuntil theconditionspecifiedinthewhileloopissatisfied.Itisalso calledapre-testedloop.  Thesyntaxofwhileloopinclanguageisgivenbelow: initialization; While(condition) { blockofthestatementstobeexecuted; increment; } While loop in C
  9. 9.  Thedo-whileloopcontinuesuntilagivencondition satisfies.Itisalsocalledposttestedloop.Itisusedwhenitis necessarytoexecutetheloopatleastonce(mostlymenu drivenprograms).  Thesyntaxofdo-whileloopinclanguageisgivenbelow; do { codetobeexecuted; } While(condition); Do-while loop in C
  10. 10. • TheforloopinC languageisusedtoiteratethe statementsorapartoftheprogramseveraltimes.It isfrequentlyusedtotraversethedatastructureslike thearrayandlinkedlist. •Thesyntaxofforloopinclanguageisgivenbelow: for(expression1;Expression2;Expression3) { codestobeexecuted; } For loop in C
  11. 11.  Expression 1 (Optional) • Representstheinitializationoftheloopvariable. •Morethanonevariablecanbeinitialized.  Expression 2 •Expression2isaconditionalexpression.Itchecksfora specificconditiontobesatisfied.Ifitisnot,theloopis terminated. •Expression2canhavemorethanonecondition.However, theloopwilliterateuntilthelastconditionbecomesfalse. Otherconditionswillbetreatedasstatements.  Expression3 • Expression 3 is increment or decrement to update the value of the loop variable
  12. 12.  Flowchart : For the or loop
  13. 13. { Example of While loop print even numbers 1. //print even numbers 2. #include<stdio.h> 3. int main ( ) 4. { 5. int n, i=0; 6. printf (“/n Enter a number : “) ; 7. scanf(“ % d” ,&n); 8. while ( i < = n ) 9. { 10. if ( i % 2= =0) 11. printf (“/n%d” , i ) ; 12. i + +; 13. } 14. return 0
  14. 14. Example of a DO-while loop
  15. 15. Example of a For Loop in C

×