SlideShare a Scribd company logo
SWITCH CASE SAMPLE
                  &
LOOPING CASE SAMPLE
         HTTP://EGLOBIOTRAINING.COM/
SWITCH CASE STATEMENT

 In programming, a switch, case, select or inspect statement is a type of
selection control mechanism that exists in most imperative
programming languages such as Pascal, Ada, C/C++, C#, Java, and so on. It
is also included in several other types of languages in programming. Its
purpose is to allow the value of a variable or expression to control the flow of
program execution via a multiway branch. The main reasons for using a switch
include improving clarity, by reducing otherwise repetitive coding, and also
offering the potential for faster execution through easier compiler
optimization in many cases of programming.

                                                       http://eglobiotraining.com/
In programming, the switch statement passes control to the statement following
one of the labels or to the statement following the switch body. The value of the
expression that precedes the switch body determines which statement receives
control. This expression is called the switch expression.
In the programming the value of the switch expression is compared with the value
of the expression in each case label. If a matching value is found, control is
passed to the statement following the case label that contains the matching value.
If there is no matching value but there is a default label in the switch body, control
passes to the default labeled statement. If no matching value is found, and there
is no default label anywhere in the switch body, no part of the switch body is
processed.
When control passes in programming to a statement in the switch body, control
only leaves the switch body when a break statement is encountered or the last
statement in the switch body is processed.
If necessary, in programming an integral promotion is performed on the controlling
expression, and all expressions in the case statements are converted to the same
type as the controlling expression. The switch expression can also be of class
type if there is a single conversion to integral or enumeration type.
Compiling with option -qinfo=gen finds case labels that fall through when they
should not.

                                                           http://eglobiotraining.com/
 In programming, the if...else if...else Statement:
     In programming, an if statement can be followed by an
  optional else if...else statement, which is very useful to test
various conditions using single if...else if statement. When using
if , else if , else statements in the programming languages there
are few points to keep in mind. An if can have zero or one else's
and it must come after any else if's. An if can have zero to many
  else if's and they must come before the else. Once an else if
succeeds, none of he remaining else if's or else's will be tested.
                                        http://eglobiotraining.com/
 In programming, If the value of expression is nonzero, statement1 is
executed. If the optional else is present, statement2 is executed if the value
of expression is zero. expression must be of arithmetic or pointer type, or it
must be of a class type that defines an unambiguous conversion to an
arithmetic or pointer type. In both forms of the if statement, expression, which
can have any value except a structure, is evaluated, including all side effects.
In the programming control passes from the if statement to the next statement
in the program unless one of the statements contains a break, continue,
or goto. The else clause of an if...else statement is associated with the closest
previous if statement in the same scope that does not have a
corresponding else statement. For this sample to be unambiguous
about if...else pairing, uncomment the braces.
                                                             http://eglobiotraining.com/
C++ Programming if else statement


 If-else statement
It is similar to if statement i.e. It is also used to execute or ignore a set of
statements after testing a condition in programming language.
 In if-else statement one condition and two blocks of statements are
given.
 First blocks contain if statement with condition and its body part.
 Second is else and it contain only body part.

                                                 http://eglobiotraining.com/
Explanation working of if-else statement in programming languages

 A condition is a logical or relational expression and it produces either
true or false result.

 If the condition is true the first block of if-else statement(which is if-
statement) is executed and second is ignored and after executing the first block
, the control is transferred to nextstatement after if -else structure.

 If the condition is false then the first blocks of statement is ignored and the
second block of statement is executed. After the executing the second block
of statement the control is transferred to next statement after if-else structure.



                                                         http://eglobiotraining.com/
#include<iostream>

               #include<stdlib.h>

             using namespace std;

                   int main ()

                        {

int number_of_units, tuitionfee, paymentforunits;

cout<< "number of units you are to enroll:nn";

            cin>>number_of_units;

    paymentforunits=number_of_units*150;

              cout<<"payment for
         units:nn"<<paymentforunits;

     tuitionfee=paymentforunits+15%+20;

      cout<<"tuition fee:nn"<<tuitionfee;

               system(“PAUSE");

                    return 0;

                        }

                      http://eglobiotraining.com/
#include<stdlib.h>
      #include<iostream>
     using namespace std;
           int main()
                {
         char gender;
 cout<<"Enter your Gender.";
         cin>>gender;
if (gender == 'M'||gender == 'm')
         cout<<"Male";
              else
       cout<<"Female";
        cout<<"nnn";
      system(“PAUSE");
            return 0;
                }
                               http://eglobiotraining.com/
#include<stdlib.h>
                   #include<iostream>
                    #include<stdio.h>
                   #include<conio.h>
                  using namespace std;
                        int main()
                            {
float total_purchase=0, purchase_discount = 0, net_bill=0;
     cout<<"PLEASE INPUT TOTAL PURCHASE: ";
                  cin>>total_purchase;
               if (total_purchase >=2000)
       purchase_discount = total_purchase*0.10;
              cout<<"THE DISCOUNT IS:";
               cout<<purchase_discount;
     net_bill = (total_purchase)-purchase_discount;
             cout<<"nYOUR NET BILL IS:";
                     cout<<net_bill;
                   system("PAUSE");
                        return 0;
                            }

                                                http://eglobiotraining.com/
#include<iostream>

     #include<stdlib.h>

   using namespace std;

         int main ()

              {

         int speed;

cout<<"enter speed in kph:" ;

        cin>>speed;

        cin.ignore();

if (speed >= 80||speed <=99 )

                      {

        cout<<"500";

                      }

   else if (speed <= 100)

                      {

        cout<<"250";

                      }

            else

         cout<<"0";

         cin.get ();

     system("PAUSE");

          return 0;

                  }

                                http://eglobiotraining.com/
#include<stdlib.h>

       #include<iostream>

      using namespace std;

            int main()

                 {

             int year;

 cout<<"Enter student year; n" ;

           cin>> year ;

          cin. ignore () ;

          if (year == 1){

      cout<< "Freshmen";

                     }

          if (year == 2)

                     {

cout<< "Secondary or Sophomore";

                     }

          if (year == 3)

                     {

   cout<< "Tersiary or Junior";

                     }

          if (year == 4)

                     {

     cout<< "Old or Senior";

                     }

        else if (year == 4)

                 {

         cout<< "Error";

                         }

            cin.get () ;

       system ("PAUSE") ;

             return 0;

                 }



                                    http://eglobiotraining.com/
LOOPING STATEMENT
 In computer science a for loop is a programming language statement which allows
code to be repeatedly executed. A for loop is classified as an iteration statement. Unlike
many other kinds of loops, such as the while loop, the for loop is often distinguished by an
explicit loop counter or loop variable. This allows the body of the for loop to know about the
sequencing of each iteration. For loops are also typically used when the number of iterations
is known before entering the loop. In programming loops are the shorthand way to make
loops when the number of iterations is known, as a for loop can be written as a while loop.
The name for loop comes from the English word for, which is used as the keyword in most
programming languages to introduce a for loop. The loop body is executed "for" the given
values of the loop variable, though this is more explicit in the ALGOL version of the
statement, in which a list of possible values and/or increments can be specified.
In FORTRAN and PL/I though, the keyword DO is used and it is called a do loop, but it is
otherwise identical to the for loop described here and is not to be confused with the Do while
loop.

                                                                     http://eglobiotraining.com/
 In computer programming, a loop is a sequence of instruction s that is
continually repeated until a certain condition is reached. Typically, a certain
process is done, such as getting an item of data and changing it, and then
some condition is checked such as whether a counter has reached a
prescribed number. If it hasn't, the next instruction in the sequence is an
instruction to return to the first instruction in the sequence and repeat the
sequence. If the condition has been reached, the next instruction "falls through"
to the next sequential instruction or branches outside the loop. A loop is a
fundamental programming idea that is commonly used in writing programs.
                                                        http://eglobiotraining.com/
KINDS OF FOR LOOPS
 A for loop statement is available in most imperative programming languages. Even
ignoring minor differences in syntax there are many differences in how these statements
work and the level of expressiveness they support. Generally, for loops fall into one of the
following categories:
Iterator-based for loops
In programming, this type of for loop is a falsification of the numeric range type of for loop;
   as it allows for the enumeration of sets of items other than number sequences. It is
usually characterized by the use of an implicit or explicit iterator, in which the loop variable
      takes on each of the values in a sequence or other order able data collection.


                                                                    http://eglobiotraining.com/
 Vectorised for loops
 Some languages of programming offer a for loop that acts as if processing all
iterations in parallel, such as the for all keyword in FORTRAN 95 which has the
        interpretation that all right-hand-side expressions are evaluated
 before any assignments are made, as distinct from the explicit iteration form.
 For example of the programming in the for loop in the following pseudo code
fragment, when calculating the new value for A(i), except for the first (with i = 2)
the reference to A(i - 1) will obtain the new value that had been placed there in
the previous step. In the for all version, however, each calculation refers only to
                             the original, unaltered A.
                                                          http://eglobiotraining.com/
 Compound for loops
In programming, A value is assigned to the loop variable i and only if
 the while expression is true will the loop body be executed. If the
 result were false the for-loop's execution stops short. Granted that
   for programming the loop variable's value is defined after the
 termination of the loop, then the above statement will find the first
non-positive element in array A (and if no such, its value will be N +
  1), or, with suitable variations, the first non-blank character in a
                          string, and so on.
                                               http://eglobiotraining.com/
 while ( expression ) statement
In programming a while loop, the expression is evaluated. If nonzero,
the statement executes, and the expression is evaluated again. This happens over and over
until the expression's value is zero. If the expression is zero the first time it is
evaluated, statement is not executed at all in the programming.

 Do statement while ( expression);
In programming a do while loop is just like a plain while loop, except the statement
executes before the expression is evaluated. Thus, the statement in programming
languages will always be evaluated at least once.

 for ( expression1; expression2; expression3 )statement
In programming a for loop, first expression1 is evaluated. Then expression2 is evaluated,
and if it is zero EEL leaves the loop and begins executing instructions after statement.
Otherwise the statement in programming languages is executed, expression3 is evaluated,
and expression2 is evaluated again, continuing until expression2 is zero. You can omit any
of the expressions. If you omit expression2, it is like expression2 is nonzero. while
(expression) is the same as for (; expression; ). The syntax for (;;) creates an endless loop
that must be exited using the break statement in the programming.

                                                                         http://eglobiotraining.com/
#include <iostream>

            using namespace std;

                  int main(){

                    int a;

cout << "How many times do you want to eat? ";

                  cin >> a;

                  while (a){

              cout << a << "n";

                     --a;

                       }

              system("PAUSE");

                   cin.get();

                  return 0;

                       }

                      http://eglobiotraining.com/
#include<iostream>

                    #include<string>

                       int main()

                            {

                 using namespace std;

             string password, finalsnamin;

               finalsnamin="finalsnamin";

      cout<<"Enter the correct password"<<endl;

                          do{

cout<<"Enter the correct password to obtain satisfaction:
                           ";

                    cin>> password;

            }while (password!=finalsnamin);

             cout<<"You've got it!"<<endl;

                   system("pause");

                       return (0);

                            }

                                http://eglobiotraining.com
#include <iostream>
          #include <string>
         using namespace std;
             int main(){
         string choice = "y";
       while ( choice == "y" ){
cout << "You are in the loop" << endl;
   cout << "Loop again?" << endl;
            cin >> choice;
                  }
cout << "You exited the loop" << endl;
           system("PAUSE");
                cin.get();
                  }
               http://eglobiotraining.com/
#include<iostream>
             #include<string>
                int main()
                     {
          using namespace std;
          string password, love;
               love="love";
cout<<"Enter the correct password"<<endl;
                    do{
cout<<"Enter the correct password to obtain
              satisfaction: ";
             cin>> password;
         }while (password!=love);
       cout<<"You've got it!"<<endl;
             system("pause");
                return (0);
                     }
                                 http://eglobiotraining.com
#include <iostream>
        using namespace std;
             int main(){
                int a;
cout << "How many hours do we need to
          sleep? ";cin >> a;
              while (a){
          cout << a << "n";
                 --a;
                  }
           system("PAUSE");
               cin.get();
              return 0;
                  }
                 http://eglobiotraining.com/
THE FINAL
       REQUIREMENT FOR
       FUNDAMENTALS OF
         PROGRAMMING

Submitted to : Prof. Erwin Globio



                                    Sumbitted by : Xhyna Mea Delfin

More Related Content

What's hot (20)

PPT
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
PPT
C Tutorials
Sudharsan S
 
PPTX
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 
PPSX
C lecture 3 control statements slideshare
Gagan Deep
 
PPTX
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
 
PPTX
Conditional and control statement
narmadhakin
 
PDF
7 rules of simple and maintainable code
Geshan Manandhar
 
PDF
6 c control statements branching &amp; jumping
MomenMostafa
 
PDF
Data structure scope of variables
Saurav Kumar
 
PPTX
Php operators
Aashiq Kuchey
 
DOC
3. control statement
Shankar Gangaju
 
PPTX
Powerpoint presentation final requirement in fnd prg
alyssa-castro2326
 
PPTX
C if else
Ritwik Das
 
PPTX
Conditional Statement in C Language
Shaina Arora
 
PDF
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
PDF
Swift Introduction
Giuseppe Arici
 
PPTX
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
PPT
Lecture 10 - Control Structures 2
Md. Imran Hossain Showrov
 
PPT
C tutorial
tuncay123
 
PPT
C tutorial
Khan Rahimeen
 
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
C Tutorials
Sudharsan S
 
CONDITIONAL STATEMENT IN C LANGUAGE
Ideal Eyes Business College
 
C lecture 3 control statements slideshare
Gagan Deep
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
P3 InfoTech Solutions Pvt. Ltd.
 
Conditional and control statement
narmadhakin
 
7 rules of simple and maintainable code
Geshan Manandhar
 
6 c control statements branching &amp; jumping
MomenMostafa
 
Data structure scope of variables
Saurav Kumar
 
Php operators
Aashiq Kuchey
 
3. control statement
Shankar Gangaju
 
Powerpoint presentation final requirement in fnd prg
alyssa-castro2326
 
C if else
Ritwik Das
 
Conditional Statement in C Language
Shaina Arora
 
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
Swift Introduction
Giuseppe Arici
 
Decision Making Statement in C ppt
MANJUTRIPATHI7
 
Lecture 10 - Control Structures 2
Md. Imran Hossain Showrov
 
C tutorial
tuncay123
 
C tutorial
Khan Rahimeen
 

Viewers also liked (18)

PPTX
Music magazine skills development
Annie Evans
 
PPTX
Represent
rowanallen29
 
PPTX
R epresent
rowanallen29
 
PPTX
Creating for a Living
Laura West
 
PPTX
Music magazine
Annie Evans
 
PPTX
Evaluation Question 3
Annie Evans
 
PPTX
R epresent
rowanallen29
 
PPTX
Audience research
Annie Evans
 
PDF
Creating for a Living Series
Laura West
 
PPTX
Phishing
Joshua Maldonado
 
PPTX
Skills Development
Annie Evans
 
PPTX
Audience research
Annie Evans
 
PPTX
Supply list audacious business goddess
Laura West
 
PPTX
Audience research
Annie Evans
 
DOCX
Assignement 3 ADV report (1)
Riddhi Shah
 
PPTX
Las nueve musas griegas
Ruben Balmaseda
 
PPTX
Hemocromatosis hereditaria-tipo-1
Paloma Hein Cardenas
 
PPTX
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisser
i1legacy
 
Music magazine skills development
Annie Evans
 
Represent
rowanallen29
 
R epresent
rowanallen29
 
Creating for a Living
Laura West
 
Music magazine
Annie Evans
 
Evaluation Question 3
Annie Evans
 
R epresent
rowanallen29
 
Audience research
Annie Evans
 
Creating for a Living Series
Laura West
 
Skills Development
Annie Evans
 
Audience research
Annie Evans
 
Supply list audacious business goddess
Laura West
 
Audience research
Annie Evans
 
Assignement 3 ADV report (1)
Riddhi Shah
 
Las nueve musas griegas
Ruben Balmaseda
 
Hemocromatosis hereditaria-tipo-1
Paloma Hein Cardenas
 
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisser
i1legacy
 
Ad

Similar to Computer programming (20)

PPTX
Switch case and looping new
aprilyyy
 
PPTX
Switch case and looping kim
kimberly_Bm10203
 
PPTX
Switch case and looping
aprilyyy
 
PPT
Fundamentals of programming angeli
bergonio11339481
 
PPTX
Final project powerpoint template (fndprg) (1)
heoff
 
PPTX
Switch case and looping
ChaAstillas
 
PPTX
Final requirement in programming
trish_maxine
 
PPTX
My final requirement
katrinaguevarra29
 
PDF
Fundamentals of programming)
jakejakejake2
 
PPTX
Yeahhhh the final requirement!!!
olracoatalub
 
PPTX
Switch case looping
Cherimay Batallones
 
PPTX
Fundamentals of prog. by rubferd medina
rurumedina
 
PPT
My programming final proj. (1)
aeden_brines
 
PDF
C++ Course - Lesson 1
Mohamed Ahmed
 
PPTX
Final requirement
arjoy_dimaculangan
 
PPTX
Project in programming
sahashi11342091
 
PDF
4. programing 101
IEEE MIU SB
 
PDF
C++ control structure
bluejayjunior
 
PPTX
Castro
JenineCastro
 
PPTX
Final project powerpoint template (fndprg) (1)
jewelyngrace
 
Switch case and looping new
aprilyyy
 
Switch case and looping kim
kimberly_Bm10203
 
Switch case and looping
aprilyyy
 
Fundamentals of programming angeli
bergonio11339481
 
Final project powerpoint template (fndprg) (1)
heoff
 
Switch case and looping
ChaAstillas
 
Final requirement in programming
trish_maxine
 
My final requirement
katrinaguevarra29
 
Fundamentals of programming)
jakejakejake2
 
Yeahhhh the final requirement!!!
olracoatalub
 
Switch case looping
Cherimay Batallones
 
Fundamentals of prog. by rubferd medina
rurumedina
 
My programming final proj. (1)
aeden_brines
 
C++ Course - Lesson 1
Mohamed Ahmed
 
Final requirement
arjoy_dimaculangan
 
Project in programming
sahashi11342091
 
4. programing 101
IEEE MIU SB
 
C++ control structure
bluejayjunior
 
Castro
JenineCastro
 
Final project powerpoint template (fndprg) (1)
jewelyngrace
 
Ad

Computer programming

  • 1. SWITCH CASE SAMPLE & LOOPING CASE SAMPLE HTTP://EGLOBIOTRAINING.COM/
  • 2. SWITCH CASE STATEMENT  In programming, a switch, case, select or inspect statement is a type of selection control mechanism that exists in most imperative programming languages such as Pascal, Ada, C/C++, C#, Java, and so on. It is also included in several other types of languages in programming. Its purpose is to allow the value of a variable or expression to control the flow of program execution via a multiway branch. The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and also offering the potential for faster execution through easier compiler optimization in many cases of programming. http://eglobiotraining.com/
  • 3. In programming, the switch statement passes control to the statement following one of the labels or to the statement following the switch body. The value of the expression that precedes the switch body determines which statement receives control. This expression is called the switch expression. In the programming the value of the switch expression is compared with the value of the expression in each case label. If a matching value is found, control is passed to the statement following the case label that contains the matching value. If there is no matching value but there is a default label in the switch body, control passes to the default labeled statement. If no matching value is found, and there is no default label anywhere in the switch body, no part of the switch body is processed. When control passes in programming to a statement in the switch body, control only leaves the switch body when a break statement is encountered or the last statement in the switch body is processed. If necessary, in programming an integral promotion is performed on the controlling expression, and all expressions in the case statements are converted to the same type as the controlling expression. The switch expression can also be of class type if there is a single conversion to integral or enumeration type. Compiling with option -qinfo=gen finds case labels that fall through when they should not. http://eglobiotraining.com/
  • 4.  In programming, the if...else if...else Statement: In programming, an if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if , else if , else statements in the programming languages there are few points to keep in mind. An if can have zero or one else's and it must come after any else if's. An if can have zero to many else if's and they must come before the else. Once an else if succeeds, none of he remaining else if's or else's will be tested. http://eglobiotraining.com/
  • 5.  In programming, If the value of expression is nonzero, statement1 is executed. If the optional else is present, statement2 is executed if the value of expression is zero. expression must be of arithmetic or pointer type, or it must be of a class type that defines an unambiguous conversion to an arithmetic or pointer type. In both forms of the if statement, expression, which can have any value except a structure, is evaluated, including all side effects. In the programming control passes from the if statement to the next statement in the program unless one of the statements contains a break, continue, or goto. The else clause of an if...else statement is associated with the closest previous if statement in the same scope that does not have a corresponding else statement. For this sample to be unambiguous about if...else pairing, uncomment the braces. http://eglobiotraining.com/
  • 6. C++ Programming if else statement  If-else statement It is similar to if statement i.e. It is also used to execute or ignore a set of statements after testing a condition in programming language.  In if-else statement one condition and two blocks of statements are given.  First blocks contain if statement with condition and its body part.  Second is else and it contain only body part. http://eglobiotraining.com/
  • 7. Explanation working of if-else statement in programming languages  A condition is a logical or relational expression and it produces either true or false result.  If the condition is true the first block of if-else statement(which is if- statement) is executed and second is ignored and after executing the first block , the control is transferred to nextstatement after if -else structure.  If the condition is false then the first blocks of statement is ignored and the second block of statement is executed. After the executing the second block of statement the control is transferred to next statement after if-else structure. http://eglobiotraining.com/
  • 8. #include<iostream> #include<stdlib.h> using namespace std; int main () { int number_of_units, tuitionfee, paymentforunits; cout<< "number of units you are to enroll:nn"; cin>>number_of_units; paymentforunits=number_of_units*150; cout<<"payment for units:nn"<<paymentforunits; tuitionfee=paymentforunits+15%+20; cout<<"tuition fee:nn"<<tuitionfee; system(“PAUSE"); return 0; } http://eglobiotraining.com/
  • 9. #include<stdlib.h> #include<iostream> using namespace std; int main() { char gender; cout<<"Enter your Gender."; cin>>gender; if (gender == 'M'||gender == 'm') cout<<"Male"; else cout<<"Female"; cout<<"nnn"; system(“PAUSE"); return 0; } http://eglobiotraining.com/
  • 10. #include<stdlib.h> #include<iostream> #include<stdio.h> #include<conio.h> using namespace std; int main() { float total_purchase=0, purchase_discount = 0, net_bill=0; cout<<"PLEASE INPUT TOTAL PURCHASE: "; cin>>total_purchase; if (total_purchase >=2000) purchase_discount = total_purchase*0.10; cout<<"THE DISCOUNT IS:"; cout<<purchase_discount; net_bill = (total_purchase)-purchase_discount; cout<<"nYOUR NET BILL IS:"; cout<<net_bill; system("PAUSE"); return 0; } http://eglobiotraining.com/
  • 11. #include<iostream> #include<stdlib.h> using namespace std; int main () { int speed; cout<<"enter speed in kph:" ; cin>>speed; cin.ignore(); if (speed >= 80||speed <=99 ) { cout<<"500"; } else if (speed <= 100) { cout<<"250"; } else cout<<"0"; cin.get (); system("PAUSE"); return 0; } http://eglobiotraining.com/
  • 12. #include<stdlib.h> #include<iostream> using namespace std; int main() { int year; cout<<"Enter student year; n" ; cin>> year ; cin. ignore () ; if (year == 1){ cout<< "Freshmen"; } if (year == 2) { cout<< "Secondary or Sophomore"; } if (year == 3) { cout<< "Tersiary or Junior"; } if (year == 4) { cout<< "Old or Senior"; } else if (year == 4) { cout<< "Error"; } cin.get () ; system ("PAUSE") ; return 0; } http://eglobiotraining.com/
  • 13. LOOPING STATEMENT  In computer science a for loop is a programming language statement which allows code to be repeatedly executed. A for loop is classified as an iteration statement. Unlike many other kinds of loops, such as the while loop, the for loop is often distinguished by an explicit loop counter or loop variable. This allows the body of the for loop to know about the sequencing of each iteration. For loops are also typically used when the number of iterations is known before entering the loop. In programming loops are the shorthand way to make loops when the number of iterations is known, as a for loop can be written as a while loop. The name for loop comes from the English word for, which is used as the keyword in most programming languages to introduce a for loop. The loop body is executed "for" the given values of the loop variable, though this is more explicit in the ALGOL version of the statement, in which a list of possible values and/or increments can be specified. In FORTRAN and PL/I though, the keyword DO is used and it is called a do loop, but it is otherwise identical to the for loop described here and is not to be confused with the Do while loop. http://eglobiotraining.com/
  • 14.  In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached. Typically, a certain process is done, such as getting an item of data and changing it, and then some condition is checked such as whether a counter has reached a prescribed number. If it hasn't, the next instruction in the sequence is an instruction to return to the first instruction in the sequence and repeat the sequence. If the condition has been reached, the next instruction "falls through" to the next sequential instruction or branches outside the loop. A loop is a fundamental programming idea that is commonly used in writing programs. http://eglobiotraining.com/
  • 15. KINDS OF FOR LOOPS  A for loop statement is available in most imperative programming languages. Even ignoring minor differences in syntax there are many differences in how these statements work and the level of expressiveness they support. Generally, for loops fall into one of the following categories: Iterator-based for loops In programming, this type of for loop is a falsification of the numeric range type of for loop; as it allows for the enumeration of sets of items other than number sequences. It is usually characterized by the use of an implicit or explicit iterator, in which the loop variable takes on each of the values in a sequence or other order able data collection. http://eglobiotraining.com/
  • 16.  Vectorised for loops Some languages of programming offer a for loop that acts as if processing all iterations in parallel, such as the for all keyword in FORTRAN 95 which has the interpretation that all right-hand-side expressions are evaluated before any assignments are made, as distinct from the explicit iteration form. For example of the programming in the for loop in the following pseudo code fragment, when calculating the new value for A(i), except for the first (with i = 2) the reference to A(i - 1) will obtain the new value that had been placed there in the previous step. In the for all version, however, each calculation refers only to the original, unaltered A. http://eglobiotraining.com/
  • 17.  Compound for loops In programming, A value is assigned to the loop variable i and only if the while expression is true will the loop body be executed. If the result were false the for-loop's execution stops short. Granted that for programming the loop variable's value is defined after the termination of the loop, then the above statement will find the first non-positive element in array A (and if no such, its value will be N + 1), or, with suitable variations, the first non-blank character in a string, and so on. http://eglobiotraining.com/
  • 18.  while ( expression ) statement In programming a while loop, the expression is evaluated. If nonzero, the statement executes, and the expression is evaluated again. This happens over and over until the expression's value is zero. If the expression is zero the first time it is evaluated, statement is not executed at all in the programming.  Do statement while ( expression); In programming a do while loop is just like a plain while loop, except the statement executes before the expression is evaluated. Thus, the statement in programming languages will always be evaluated at least once.  for ( expression1; expression2; expression3 )statement In programming a for loop, first expression1 is evaluated. Then expression2 is evaluated, and if it is zero EEL leaves the loop and begins executing instructions after statement. Otherwise the statement in programming languages is executed, expression3 is evaluated, and expression2 is evaluated again, continuing until expression2 is zero. You can omit any of the expressions. If you omit expression2, it is like expression2 is nonzero. while (expression) is the same as for (; expression; ). The syntax for (;;) creates an endless loop that must be exited using the break statement in the programming. http://eglobiotraining.com/
  • 19. #include <iostream> using namespace std; int main(){ int a; cout << "How many times do you want to eat? "; cin >> a; while (a){ cout << a << "n"; --a; } system("PAUSE"); cin.get(); return 0; } http://eglobiotraining.com/
  • 20. #include<iostream> #include<string> int main() { using namespace std; string password, finalsnamin; finalsnamin="finalsnamin"; cout<<"Enter the correct password"<<endl; do{ cout<<"Enter the correct password to obtain satisfaction: "; cin>> password; }while (password!=finalsnamin); cout<<"You've got it!"<<endl; system("pause"); return (0); } http://eglobiotraining.com
  • 21. #include <iostream> #include <string> using namespace std; int main(){ string choice = "y"; while ( choice == "y" ){ cout << "You are in the loop" << endl; cout << "Loop again?" << endl; cin >> choice; } cout << "You exited the loop" << endl; system("PAUSE"); cin.get(); } http://eglobiotraining.com/
  • 22. #include<iostream> #include<string> int main() { using namespace std; string password, love; love="love"; cout<<"Enter the correct password"<<endl; do{ cout<<"Enter the correct password to obtain satisfaction: "; cin>> password; }while (password!=love); cout<<"You've got it!"<<endl; system("pause"); return (0); } http://eglobiotraining.com
  • 23. #include <iostream> using namespace std; int main(){ int a; cout << "How many hours do we need to sleep? ";cin >> a; while (a){ cout << a << "n"; --a; } system("PAUSE"); cin.get(); return 0; } http://eglobiotraining.com/
  • 24. THE FINAL REQUIREMENT FOR FUNDAMENTALS OF PROGRAMMING Submitted to : Prof. Erwin Globio Sumbitted by : Xhyna Mea Delfin