SlideServe
Menu
Préférences
© SlideServe · v2026

COMPUTER SCIENCE

claire avatar
16 diapositives · 332 Views · Aug 22, 2014

COMPUTER SCIENCE. PROJECT WORK. PREPARED BY-. ANUJ AND ANKIT CLASS XI-SCIENCE ROLL NO-02 AND 38. FLOW OF CONTROL. LOOP PROGRAMMING. TOPIC. FOR LOOP WHILE LOOP DO-WHILE LOOP. THE FOR LOOP.

COMPUTER SCIENCE - slide 1
01 / 16COMPUTER SCIENCE
1 / 17

Télécharger la présentation

COMPUTER SCIENCE
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. COMPUTER SCIENCE PROJECT WORK

  2. PREPARED BY- ANUJ AND ANKIT CLASS XI-SCIENCE ROLL NO-02 AND 38

  3. FLOW OF CONTROL LOOP PROGRAMMING

  4. TOPIC FOR LOOP WHILE LOOP DO-WHILE LOOP

  5. THE FOR LOOP The for loop is the easiest to understand of the C++ loops. All its loop control elements are gathered in one place (on the top of the loop), while in the other loop construction of C++,they (top control elements) are scattered about the program. The general form (syntax) of the for loop statement is

  6. for (initialization expression(s); test expression;update expression(s) )body- of –the- loop; The following examples illustrates the use of for statement

  7. Program using loop to print numbers from 1 to10 #include<iostream.h> int main() { int i; //declaring variable i for (i=1;i<=10;i++) cout<<i; return 0; } Output 12345678910

  8. The following lines explain the working of the above given for loop cout<<i; Body of loop

  9. Firstly initialization expression is executed .i.e i=1 which gives the first value 1 to variable i. • Then the test expression is evaluated. i.e. , i<=10 which results into true i.e.1 . • Since the test expression is true , the body of loop i.e. cout<<i is executed which prints the current value of i . • After executing the loop body the update expression i.e. i++ is executed which increments the value of i. • After the update expression is executed the test expression is again evaluated. If it is true the sequence is repeated from step no. 3,otherwise the loop terminates Following figure outlines the working of a For loop:

  10. Initialization expression Test Expression false exit true Body of loop Update expression

  11. The while Loop • The second loop available in C++ is the While loop. The while loop is an entry-controlled loop . The syntax of a while loop is While (expression) loop-body

  12. Program to calculate the factorial of an integer #include<iostream.h> int main() { Unsigned long i, num, fact=1; cout<<“Enter Integer:”; cin>>num; //num gets its 1st value. while(num) { fact=fact*num ; --num; } Cout” the factorial of”<<i<<“is”<<fact<<“\n”; getch() }

  13. Output of the above program. Enter Integer :10 The factorial of 10 is 3628800

  14. The do-while loop Unlike the for and while loops, the do-while is an exit –controlled loop i.e., it evaluates its test expression at the bottom of the loop after executing its loop-body statements. This means that a do-while loop always executes at least once. In the other two loops for and while, the test -expression is evaluated at the beginning of the loop i.e., before the executing the loop –body. If the test -expressions evaluates to false the first time itself,the loop is never executed .But in some situation , it is wanted that the loop-body is executed at least once, no matter what the intial state of the test-expression is .In such cases, the do-while loop is the obvious choice . The syntax of the do-while loop is

  15. Do { Statement; }while (test-expression); The braces { } are not necessary when the loop body contains single statement.The following do-while loop prints all upper-case letters:

  16. char ch = ‘A’; do { cout<<“\n”<<ch; ch++ }while (ch<= ‘Z’ ); The above code prints characters from ‘A’ onwards until the condition ch<=‘Z’ becomes false.