SlideShare una empresa de Scribd logo
1 de 24
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

Más contenido relacionado

La actualidad más candente

C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshareGagan Deep
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsP3 InfoTech Solutions Pvt. Ltd.
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statementnarmadhakin
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable codeGeshan Manandhar
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumpingMomenMostafa
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variablesSaurav Kumar
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgalyssa-castro2326
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsDhivyaSubramaniyam
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C pptMANJUTRIPATHI7
 

La actualidad más candente (20)

Lecture 14 - Scope Rules
Lecture 14 - Scope RulesLecture 14 - Scope Rules
Lecture 14 - Scope Rules
 
C Tutorials
C TutorialsC Tutorials
C Tutorials
 
CONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGECONDITIONAL STATEMENT IN C LANGUAGE
CONDITIONAL STATEMENT IN C LANGUAGE
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
Python Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and LoopsPython Programming Essentials - M16 - Control Flow Statements and Loops
Python Programming Essentials - M16 - Control Flow Statements and Loops
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
 
6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping6 c control statements branching &amp; jumping
6 c control statements branching &amp; jumping
 
Data structure scope of variables
Data structure scope of variablesData structure scope of variables
Data structure scope of variables
 
Php operators
Php operatorsPhp operators
Php operators
 
3. control statement
3. control statement3. control statement
3. control statement
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prg
 
C if else
C if elseC if else
C if else
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
 
Swift Introduction
Swift IntroductionSwift Introduction
Swift Introduction
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2Lecture 10 - Control Structures 2
Lecture 10 - Control Structures 2
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 

Destacado

Music magazine skills development
Music magazine skills developmentMusic magazine skills development
Music magazine skills developmentAnnie Evans
 
Creating for a Living
Creating for a Living Creating for a Living
Creating for a Living Laura West
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3Annie Evans
 
Audience research
Audience researchAudience research
Audience researchAnnie Evans
 
Creating for a Living Series
Creating for a Living SeriesCreating for a Living Series
Creating for a Living SeriesLaura West
 
Skills Development
Skills Development Skills Development
Skills Development Annie Evans
 
Audience research
Audience researchAudience research
Audience researchAnnie Evans
 
Supply list audacious business goddess
Supply list   audacious business goddessSupply list   audacious business goddess
Supply list audacious business goddessLaura West
 
Audience research
Audience researchAudience research
Audience researchAnnie Evans
 
Assignement 3 ADV report (1)
Assignement 3 ADV report (1)Assignement 3 ADV report (1)
Assignement 3 ADV report (1)Riddhi Shah
 
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisser
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal KaisserWebinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisser
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisseri1legacy
 

Destacado (18)

Music magazine skills development
Music magazine skills developmentMusic magazine skills development
Music magazine skills development
 
Represent
RepresentRepresent
Represent
 
R epresent
R epresentR epresent
R epresent
 
Creating for a Living
Creating for a Living Creating for a Living
Creating for a Living
 
Music magazine
Music magazineMusic magazine
Music magazine
 
Evaluation Question 3
Evaluation Question 3Evaluation Question 3
Evaluation Question 3
 
R epresent
R epresentR epresent
R epresent
 
Audience research
Audience researchAudience research
Audience research
 
Creating for a Living Series
Creating for a Living SeriesCreating for a Living Series
Creating for a Living Series
 
Phishing
PhishingPhishing
Phishing
 
Skills Development
Skills Development Skills Development
Skills Development
 
Audience research
Audience researchAudience research
Audience research
 
Supply list audacious business goddess
Supply list   audacious business goddessSupply list   audacious business goddess
Supply list audacious business goddess
 
Audience research
Audience researchAudience research
Audience research
 
Assignement 3 ADV report (1)
Assignement 3 ADV report (1)Assignement 3 ADV report (1)
Assignement 3 ADV report (1)
 
Las nueve musas griegas
Las nueve musas griegasLas nueve musas griegas
Las nueve musas griegas
 
Hemocromatosis hereditaria-tipo-1
Hemocromatosis hereditaria-tipo-1Hemocromatosis hereditaria-tipo-1
Hemocromatosis hereditaria-tipo-1
 
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisser
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal KaisserWebinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisser
Webinar - Hamaray Bachay Hamara Sarmaya by Dr. Kanwal Kaisser
 

Similar a Computer programming

Similar a Computer programming (20)

Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Oop object oriented programing topics
Oop object oriented programing topicsOop object oriented programing topics
Oop object oriented programing topics
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angeli
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
C++ programming
C++ programmingC++ programming
C++ programming
 
OpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ ProgrammingOpenGurukul : Language : C++ Programming
OpenGurukul : Language : C++ Programming
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Final requirement
Final requirementFinal requirement
Final requirement
 
Fundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medinaFundamentals of prog. by rubferd medina
Fundamentals of prog. by rubferd medina
 
C++ lecture 02
C++   lecture 02C++   lecture 02
C++ lecture 02
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 
Looping statement
Looping statementLooping statement
Looping statement
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 

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