The document discusses programming concepts including programming languages, switch case statements, and looping. It provides examples of how to write code using switch case statements and different types of loops (for, while, do-while). The examples demonstrate how to get user input, perform calculations, and repeat blocks of code multiple times.
Switch case statements provide an alternative to long if/else statements when comparing a variable to multiple integral values. The basic format compares the variable to case values, executing code for a matching case. A default case handles non-matching values. Loops allow code to repeat, with for, while, and do-while loops. For loops initialize/update a variable and check a condition each repetition. While loops check a condition and repeat until it's false. Loops are useful for repeating tasks like displaying lists of data.
The document discusses programming languages and different types of loops used in programming. It defines programming as using a computer language to develop applications and scripts for a computer to execute. It then describes the different types of loops - for loops, which allow initialization of a variable, checking a condition, and updating the variable; while loops, which repeat code while a condition is true; and do-while loops, which execute code at least once before checking the condition. Examples of each loop type are provided to illustrate their usage.
Programming involves using computer languages to develop applications, scripts, or other instructions for computers. It is a creative process where programmers instruct computers on tasks through programming languages. There are many programming languages available, with some of the most common being C++ and Dev C++. Programming can involve various structures like switch statements and loops to control program flow and repetition.
Programming languages allow programmers to develop computer programs and software by providing instructions to computers. They provide a framework for organizing ideas about processes and tasks. Programming is a broad field that involves writing scripts, applications, and programs using various programming languages. Common programming languages include C++ and DEV C++. Programming uses concepts like variables, data types, functions, and control structures like loops and conditional statements to manipulate data and develop programs.
The document discusses programming concepts including switch case statements, looping, and different types of loops like for, while, and do-while loops. It provides examples of how to write switch case statements to select different code blocks based on a variable's value. It also explains the different parts of for, while, and do-while loops and provides examples of each type of loop. Several short programs are included that demonstrate using loops and switch case statements to process user input and perform calculations.
The document discusses switch case statements and looping in programming. It provides examples of switch case statements that allow a program to execute different code depending on the value of a variable. It also discusses the three main types of loops - for, while, and do while loops - and provides examples of how to write each type of loop. The document is intended to help explain switch case statements and looping to programmers.
The document discusses programming concepts like switch case statements and looping. It defines programming as using a computer language to develop applications and scripts. It explains that switch case statements can be used as an alternative to long if statements to compare a variable to integral values. The basic format of a switch case is provided. It also discusses the different types of loops - for, while, and do-while loops. Examples are given to illustrate how each type of loop works.
Programming involves instructing a computer using a programming language. There are different types of loops in programming including for, while, and repeat loops. A for loop repeats a block of code a fixed number of times based on a counting variable. It has three expressions for initialization, condition, and increment. A switch statement provides a clear way to select one of many code blocks to execute based on the value of a variable.
Switch case statements provide an alternative to long if/else statements when comparing a variable to multiple integral values. The basic format compares the variable to case values, executing code for a matching case. A default case handles non-matching values. Loops allow code to repeat, with for, while, and do-while loops. For loops initialize/update a variable and check a condition each repetition. While loops check a condition and repeat until it's false. Loops are useful for repeating tasks like displaying lists of data.
The document discusses programming languages and different types of loops used in programming. It defines programming as using a computer language to develop applications and scripts for a computer to execute. It then describes the different types of loops - for loops, which allow initialization of a variable, checking a condition, and updating the variable; while loops, which repeat code while a condition is true; and do-while loops, which execute code at least once before checking the condition. Examples of each loop type are provided to illustrate their usage.
Programming involves using computer languages to develop applications, scripts, or other instructions for computers. It is a creative process where programmers instruct computers on tasks through programming languages. There are many programming languages available, with some of the most common being C++ and Dev C++. Programming can involve various structures like switch statements and loops to control program flow and repetition.
Programming languages allow programmers to develop computer programs and software by providing instructions to computers. They provide a framework for organizing ideas about processes and tasks. Programming is a broad field that involves writing scripts, applications, and programs using various programming languages. Common programming languages include C++ and DEV C++. Programming uses concepts like variables, data types, functions, and control structures like loops and conditional statements to manipulate data and develop programs.
The document discusses programming concepts including switch case statements, looping, and different types of loops like for, while, and do-while loops. It provides examples of how to write switch case statements to select different code blocks based on a variable's value. It also explains the different parts of for, while, and do-while loops and provides examples of each type of loop. Several short programs are included that demonstrate using loops and switch case statements to process user input and perform calculations.
The document discusses switch case statements and looping in programming. It provides examples of switch case statements that allow a program to execute different code depending on the value of a variable. It also discusses the three main types of loops - for, while, and do while loops - and provides examples of how to write each type of loop. The document is intended to help explain switch case statements and looping to programmers.
The document discusses programming concepts like switch case statements and looping. It defines programming as using a computer language to develop applications and scripts. It explains that switch case statements can be used as an alternative to long if statements to compare a variable to integral values. The basic format of a switch case is provided. It also discusses the different types of loops - for, while, and do-while loops. Examples are given to illustrate how each type of loop works.
Programming involves instructing a computer using a programming language. There are different types of loops in programming including for, while, and repeat loops. A for loop repeats a block of code a fixed number of times based on a counting variable. It has three expressions for initialization, condition, and increment. A switch statement provides a clear way to select one of many code blocks to execute based on the value of a variable.
The document discusses programming languages and different types of loops in programming. It provides examples of for, while, and do-while loops. A for loop initializes a variable, specifies a condition, and updates the variable on each iteration. A while loop runs code while a condition is true. A do-while loop runs code once then checks the condition on subsequent iterations. Loops allow code to repeat to produce greater results through repetition.
PHP was created by Rasmus Lerdorf in 1994 to track visitors on his personal website. It later became a popular open source scripting language embedded in HTML documents. PHP code is interpreted on the server and outputs HTML and client-side code to the browser. It supports both procedural and object-oriented programming and has a large standard library of functions.
The document provides an introduction to C++ programming including setting up a compiler, the structure of a basic C++ program, variables, and input/output. It explains that a compiler is needed to convert C++ code into an executable. The main() function is called at startup and returns an integer value. A basic "Hello World" program is shown using #include, cout, and cin.get(). Variables are declared with a data type like int or char and stored user input. Comments are added using // or /* */.
The document discusses switch case statements in programming. It provides details on the basic format and usage of switch case statements, including that they allow a variable to be tested for equality against multiple values through different cases. The document also notes some key rules for switch cases, such as requiring a break statement at the end of each case and that case values must be integer or character constants. It provides examples of switch case statements and discusses how they can provide a cleaner alternative to long if-else statements.
This document provides an introduction to PHP with 8 sections: 1) PHP stands for Hypertext Preprocessor and is a scripting language; 2) PHP can be used on Stanford servers or free web hosts; 3) A "Hello World" example is presented using print(); 4) Syntax guidelines are outlined; 5) If/else conditional statements are covered; 6) Variables are introduced; 7) Forms processing with GET and POST variables is demonstrated; 8) More advanced PHP topics are mentioned to explore further.
Presentation on major features of PHP 5.3 for the July 2009 Baltimore/Washington DC PHP Meetup. It touches on major features and changes that were made in the PHP 5.3 series
This document provides an introduction and overview of PHP for beginners. It teaches the basics of PHP so readers can customize PHP scripts, design their own PHP projects, and become more valuable to employers with PHP skills. The tutorial explains that PHP is a scripting language embedded in HTML pages that allows dynamically generated web pages. It covers PHP syntax, variables, functions like echo, strings, and basic operators. The goal is to teach PHP fundamentals while not rushing through the material too quickly.
Final project powerpoint template (fndprg) (1)jewelyngrace
The document discusses various programming topics including looping, switch case statements, and different types of loops in C++ programming such as for, while, and do while loops. Examples of each loop type are provided written in C++ code.
Switch statements and looping statements are key programming concepts. Switch statements allow a program to evaluate an expression and branch to different blocks of code based on the resulting value. Common switch statements include if/else. Looping statements let a program repeat blocks of code a specified number of times or while a condition remains true. Common looping statements include while, do/while, and for loops. Together, switch and looping statements allow programs to selectively execute code and repeat tasks as needed to process inputs and achieve the desired output.
This document provides an overview of pre-processor hypertext and core PHP concepts. It discusses software engineering, web programming, and introduces PHP as a scripting language. It covers PHP variables, expressions, operators, conditional statements, functions, arrays, syntax, strings, databases, sessions, cookies, files, email handling, JavaScript, AJAX and XML. It also discusses programming fundamentals like data types, keywords, operators, variables, conditional statements, loops, functions and object-oriented programming concepts.
JavaScript is a programming language used to make web pages interactive. It can be placed in the <body> and <head> sections of an HTML page. JavaScript code must be inserted between <script> and </script> tags. Functions and events allow JavaScript code to run when events occur, like when a user clicks a button. Scripts can also be placed in external .js files for reuse across pages. JavaScript can output data through alerts, writing to the HTML, or the browser console. Variables are used to store and work with data in JavaScript programs. Comments are used to explain code and prevent execution when needed.
PHP is a server-side scripting language designed for web development, but also used as a general-purpose programming language. Most of the websites are using PHP in their dynamic content
This document provides an introduction and overview of PHP. It states that PHP is a server-side scripting language commonly used for web development. It can be embedded into HTML and is free, efficient and compatible with many platforms and servers. The document then covers basic PHP syntax, variables, data types, operators, conditional statements and loops. It provides examples to illustrate key PHP concepts and functions.
PHP is a server-side scripting language used to create dynamic web pages. It allows embedding PHP code within HTML pages and interacting with databases. Key elements of PHP include variables, control structures, functions, and sessions. Sessions store user data on the server instead of the client to avoid cookies and allow tracking users across multiple pages.
This document provides an introduction to PHP for beginners. It explains that PHP is a free and open-source scripting language widely used for web development. It works well with technologies like HTML, CSS, JavaScript, and databases like MySQL. Some key things PHP can do include dynamically generating web page content, working with files and databases on the server, and collecting/sending form data and cookies. Reasons to use PHP include its wide compatibility across operating systems and web servers, support for many databases, cost-effectiveness, and ease of learning.
This document provides an overview of basic PHP concepts including:
- PHP syntax with opening and closing tags <?php ?>
- Language constructs like echo and print for outputting strings
- Variables, data types, operators, and functions
- Conditional statements like if/else and switch statements
- Looping with while, do/while, and for loops
- Arrays for storing multiple values
- Form handling with $_GET and $_POST superglobals
- Connecting to databases using MySQLi or PDO extensions
The document covers PHP fundamentals and is intended as an introduction for learning the language. It explains core PHP concepts through examples and explanations in a step-by-step manner over 47 sections
The document provides an introduction to PHP basics including:
- PHP code is embedded in HTML using tags and the server executes the PHP code and substitutes output into the HTML page.
- PHP supports variables, data types, operators, control structures like if/else statements and loops. Useful built-in functions allow working with forms, cookies, files, time and date.
- Server-side programming alternatives like CGI, ASP, Java Servlets, and PHP are discussed. PHP was created in 1995 and is now widely used as a free, open-source scripting language for server-side web development.
This document discusses PHP's basic syntax for escaping from HTML and embedding PHP code. It explains that PHP code is parsed between opening and closing tags like <?php ?> and is ignored outside of those tags. This allows PHP to be embedded in HTML documents. It provides examples of basic PHP embedding and also more advanced structures like if/else statements that drop in and out of PHP parsing mode. It describes the different types of PHP opening and closing tags that can be used and notes that <?php ?> tags should generally be used for portability.
This document provides an overview of PHP, including:
1. PHP is an open source scripting language suited for web development that can be embedded into HTML. It was created to allow for dynamic web pages by allowing code to be inserted directly into HTML markup.
2. PHP syntax is mostly borrowed from C and includes elements from Perl, C++, and Java. Code is embedded between <?php ?> tags which tells the server to switch into PHP mode.
3. Dynamic web pages allow content and structure to be customized on demand, for example greeting a user differently based on their language preference. Variables prefixed with $ are automatically declared when assigned.
The document discusses switch case statements and looping in programming. It provides examples of switch case statements that check the value of a variable and execute different code blocks depending on the value. It also discusses the different types of loops - for, while, and do-while loops - and provides examples of each. The examples demonstrate how to use switch cases and loops to repeat blocks of code or make decisions based on variable values.
The document discusses programming languages and different types of loops in programming. It provides examples of for, while, and do-while loops. A for loop initializes a variable, specifies a condition, and updates the variable on each iteration. A while loop runs code while a condition is true. A do-while loop runs code once then checks the condition on subsequent iterations. Loops allow code to repeat to produce greater results through repetition.
PHP was created by Rasmus Lerdorf in 1994 to track visitors on his personal website. It later became a popular open source scripting language embedded in HTML documents. PHP code is interpreted on the server and outputs HTML and client-side code to the browser. It supports both procedural and object-oriented programming and has a large standard library of functions.
The document provides an introduction to C++ programming including setting up a compiler, the structure of a basic C++ program, variables, and input/output. It explains that a compiler is needed to convert C++ code into an executable. The main() function is called at startup and returns an integer value. A basic "Hello World" program is shown using #include, cout, and cin.get(). Variables are declared with a data type like int or char and stored user input. Comments are added using // or /* */.
The document discusses switch case statements in programming. It provides details on the basic format and usage of switch case statements, including that they allow a variable to be tested for equality against multiple values through different cases. The document also notes some key rules for switch cases, such as requiring a break statement at the end of each case and that case values must be integer or character constants. It provides examples of switch case statements and discusses how they can provide a cleaner alternative to long if-else statements.
This document provides an introduction to PHP with 8 sections: 1) PHP stands for Hypertext Preprocessor and is a scripting language; 2) PHP can be used on Stanford servers or free web hosts; 3) A "Hello World" example is presented using print(); 4) Syntax guidelines are outlined; 5) If/else conditional statements are covered; 6) Variables are introduced; 7) Forms processing with GET and POST variables is demonstrated; 8) More advanced PHP topics are mentioned to explore further.
Presentation on major features of PHP 5.3 for the July 2009 Baltimore/Washington DC PHP Meetup. It touches on major features and changes that were made in the PHP 5.3 series
This document provides an introduction and overview of PHP for beginners. It teaches the basics of PHP so readers can customize PHP scripts, design their own PHP projects, and become more valuable to employers with PHP skills. The tutorial explains that PHP is a scripting language embedded in HTML pages that allows dynamically generated web pages. It covers PHP syntax, variables, functions like echo, strings, and basic operators. The goal is to teach PHP fundamentals while not rushing through the material too quickly.
Final project powerpoint template (fndprg) (1)jewelyngrace
The document discusses various programming topics including looping, switch case statements, and different types of loops in C++ programming such as for, while, and do while loops. Examples of each loop type are provided written in C++ code.
Switch statements and looping statements are key programming concepts. Switch statements allow a program to evaluate an expression and branch to different blocks of code based on the resulting value. Common switch statements include if/else. Looping statements let a program repeat blocks of code a specified number of times or while a condition remains true. Common looping statements include while, do/while, and for loops. Together, switch and looping statements allow programs to selectively execute code and repeat tasks as needed to process inputs and achieve the desired output.
This document provides an overview of pre-processor hypertext and core PHP concepts. It discusses software engineering, web programming, and introduces PHP as a scripting language. It covers PHP variables, expressions, operators, conditional statements, functions, arrays, syntax, strings, databases, sessions, cookies, files, email handling, JavaScript, AJAX and XML. It also discusses programming fundamentals like data types, keywords, operators, variables, conditional statements, loops, functions and object-oriented programming concepts.
JavaScript is a programming language used to make web pages interactive. It can be placed in the <body> and <head> sections of an HTML page. JavaScript code must be inserted between <script> and </script> tags. Functions and events allow JavaScript code to run when events occur, like when a user clicks a button. Scripts can also be placed in external .js files for reuse across pages. JavaScript can output data through alerts, writing to the HTML, or the browser console. Variables are used to store and work with data in JavaScript programs. Comments are used to explain code and prevent execution when needed.
PHP is a server-side scripting language designed for web development, but also used as a general-purpose programming language. Most of the websites are using PHP in their dynamic content
This document provides an introduction and overview of PHP. It states that PHP is a server-side scripting language commonly used for web development. It can be embedded into HTML and is free, efficient and compatible with many platforms and servers. The document then covers basic PHP syntax, variables, data types, operators, conditional statements and loops. It provides examples to illustrate key PHP concepts and functions.
PHP is a server-side scripting language used to create dynamic web pages. It allows embedding PHP code within HTML pages and interacting with databases. Key elements of PHP include variables, control structures, functions, and sessions. Sessions store user data on the server instead of the client to avoid cookies and allow tracking users across multiple pages.
This document provides an introduction to PHP for beginners. It explains that PHP is a free and open-source scripting language widely used for web development. It works well with technologies like HTML, CSS, JavaScript, and databases like MySQL. Some key things PHP can do include dynamically generating web page content, working with files and databases on the server, and collecting/sending form data and cookies. Reasons to use PHP include its wide compatibility across operating systems and web servers, support for many databases, cost-effectiveness, and ease of learning.
This document provides an overview of basic PHP concepts including:
- PHP syntax with opening and closing tags <?php ?>
- Language constructs like echo and print for outputting strings
- Variables, data types, operators, and functions
- Conditional statements like if/else and switch statements
- Looping with while, do/while, and for loops
- Arrays for storing multiple values
- Form handling with $_GET and $_POST superglobals
- Connecting to databases using MySQLi or PDO extensions
The document covers PHP fundamentals and is intended as an introduction for learning the language. It explains core PHP concepts through examples and explanations in a step-by-step manner over 47 sections
The document provides an introduction to PHP basics including:
- PHP code is embedded in HTML using tags and the server executes the PHP code and substitutes output into the HTML page.
- PHP supports variables, data types, operators, control structures like if/else statements and loops. Useful built-in functions allow working with forms, cookies, files, time and date.
- Server-side programming alternatives like CGI, ASP, Java Servlets, and PHP are discussed. PHP was created in 1995 and is now widely used as a free, open-source scripting language for server-side web development.
This document discusses PHP's basic syntax for escaping from HTML and embedding PHP code. It explains that PHP code is parsed between opening and closing tags like <?php ?> and is ignored outside of those tags. This allows PHP to be embedded in HTML documents. It provides examples of basic PHP embedding and also more advanced structures like if/else statements that drop in and out of PHP parsing mode. It describes the different types of PHP opening and closing tags that can be used and notes that <?php ?> tags should generally be used for portability.
This document provides an overview of PHP, including:
1. PHP is an open source scripting language suited for web development that can be embedded into HTML. It was created to allow for dynamic web pages by allowing code to be inserted directly into HTML markup.
2. PHP syntax is mostly borrowed from C and includes elements from Perl, C++, and Java. Code is embedded between <?php ?> tags which tells the server to switch into PHP mode.
3. Dynamic web pages allow content and structure to be customized on demand, for example greeting a user differently based on their language preference. Variables prefixed with $ are automatically declared when assigned.
The document discusses switch case statements and looping in programming. It provides examples of switch case statements that check the value of a variable and execute different code blocks depending on the value. It also discusses the different types of loops - for, while, and do-while loops - and provides examples of each. The examples demonstrate how to use switch cases and loops to repeat blocks of code or make decisions based on variable values.
Fundamentals of programming final santosAbie Santos
This document discusses programming concepts like switch case statements, looping statements, and if-else statements. It provides examples of code and explanations of how to write and run different statements in C++. It also includes links to external websites that contain additional examples of programming concepts and how they appear when compiled and executed.
A computer program is a sequence of instructions that tells a computer to perform tasks. Programs are written by programmers in human-readable source code and then compiled into an executable form for the computer to run directly. Common programming languages include C++, Java, and Python. Switch-case statements allow programmers to write code that performs different actions depending on the value of a variable.
Programming involves instructing a computer using a programming language. It allows organizing ideas about processes and things. Programming languages let programmers develop applications and scripts for computers to execute. Programming involves understanding codes, program development, and applications like web browsers. Switch cases and looping systems are important programming concepts. Switch cases allow selecting different code blocks based on a variable. Common looping structures include for, while, do-while, and foreach loops, which repeat a block of code a specified number of times. Programming requires attention to syntax and careful coding to avoid errors.
The document provides an overview of switch case and looping statements in programming. It discusses key concepts like if/else statements, switch cases, while loops, for loops, foreach loops, and break and continue statements. Examples are given for each concept along with links to online resources that demonstrate them. The document is intended to teach fundamental programming concepts for educational purposes.
Switch case and looping statements are programming constructs that allow for conditional execution of code blocks. A switch case statement allows a variable's value to control program flow via multiple branches, improving clarity over long if statements. Looping statements like while and for loops execute a block of code repeatedly, allowing programs to perform repetitive tasks or process collections of data by running the same code multiple times. These programming structures are essential for many applications to make complex decisions and process large amounts of information.
This document discusses programming concepts like switch case statements, looping statements, and programming languages. It provides examples of different types of control structures like if-else statements, for loops, while loops, and do-while loops. It also gives examples of how to write code using these structures and control flows in programming languages like C++.
This document contains information about programming languages and examples of programs written in C programming language. It discusses different programming concepts like variables, loops, switch statements, and provides 5 examples of programs using these concepts. The programs demonstrate how to print outputs based on user input or calculations using switch statements, loops, and variables. The document is meant to be submitted to Prof. Erwin M. Globio and provides resources to learn programming at http://eglobiotraining.com.
C is a programming language developed in the 1970s that is commonly used to write system software and applications. It is efficient, flexible, and requires less memory than other languages. C++ builds on C by adding object-oriented features. Programming languages use looping and conditional statements like for, while, do-while, and switch-case to control program flow and repetition. These statements allow code to be executed repeatedly or conditionally based on expressions.
This document discusses different types of loops in C++ programming including for loops, while loops, do-while loops, and infinite loops. It provides examples of each loop type and explanations of how they work. It also covers switch-case statements, providing an example case statement that prints different outputs depending on the user's input number.
The document discusses different types of looping statements in programming languages. It describes while, do-while, for, and foreach loops. It explains that while and do-while loops check a condition each iteration, for loops allow initializing and changing a counter, and foreach loops iterate over array elements. It also mentions break and continue statements that alter loop execution flow. Examples of each looping statement are provided with links to online code samples.
This document discusses different types of loops in C++ programming including for loops, while loops, do-while loops, and infinite loops. It provides examples of each loop type and explanations of how they work. It also covers switch-case statements, providing an example case statement that prints different outputs depending on the user's input number.
The document provides information about different types of loops in programming:
- Loops allow repeating a block of code a specified number of times, which is useful for tasks like displaying lists that require repeating an operation.
- A for loop repeats until a specific number of iterations is reached, as defined by its initialization, condition, and increment/decrement components.
- A while loop continuously repeats a block of code as long as a given condition remains true.
- Examples are given demonstrating the use of while and for loops to repeatedly output the values of a variable in C++.
Final requirement for programming-Bonifacio, Mary Clemenceclemencebonifacio
The document discusses programming concepts like switch case statements and looping. It provides examples of switch case statements that output the day of the week or perform calculations based on a number input. It also gives examples of different loop types like for, while, and do while loops that count or repeat outputs a specified number of times. The document is a report submitted to a professor that describes programming concepts and includes sample codes and their outputs to demonstrate switch cases and looping.
This document provides an overview of fundamental programming concepts including looping statements, switch case statements, and examples of programs using these structures. It begins with definitions of programming languages and discusses for, while, and do-while loops. Switch case statements and if/else conditional logic are also introduced. The remainder provides sample code and outputs for programs applying loops and switch cases to tasks like day selection, grading conversions, ATM transactions, and more.
The document discusses different types of looping statements in programming languages including while, do-while, for, and foreach loops. It provides examples of the syntax for each loop and explains their usage - while and do-while loops check a condition each iteration, for loops initialize and increment a counter, and foreach loops iterate over array elements. Break and continue statements are also covered which can exit or skip iterations in loops respectively.
A compiler works in several stages to translate a program from a source language to an output language. It performs lexical analysis to break the source code into tokens, syntactical analysis to check syntax is correct, semantic analysis to ensure code makes logical sense, and optionally generates intermediate code before final code generation and optimization to produce the target program.
This document is the first lesson of a C++ programming tutorial. It introduces the basics of C++, including how to set up a compiler, the structure of a basic C++ program with a main function, and how to use header files, namespaces, functions like cout and cin, and comments. The example program provided prints "Hello World" and uses cout to output text and cin.get() to pause the window until a key is pressed. Comments are explained as a way to add explanatory text to programs without affecting the code.
This document is the first lesson of a C++ programming tutorial. It introduces the basics of C++, including how to set up a compiler, the structure of a basic C++ program with a main function, and how to use header files, namespaces, functions like cout and cin, and comments. The example program provided prints "Hello World" and uses cout to output text and cin.get() to pause the window until a key is pressed. Comments are explained as a way to describe code without the compiler treating it as executable statements.
1. SWITCH CASE AND
LOOPING
A final requirement for programming
http://eglobiotraining.com
2. PROGRAMMING
We first define the word
“programming”, it is a computer language
programmers use to develop applications, scripts, or
other set of instructions for a computer to execute.
programming is instructing a
computer to do something for you with the help of a
programming language. The role of a programming
language can be described in two ways:
Technical: It is a means for instructing a Computer
to perform Tasks
Conceptual: It is a framework within which we
organize our ideas about things and processes.
http://eglobiotraining.com
3. As an individual, I have learned that programming is a very broad because it composes many
scripts, applications and can be used to run a program that has been part of the programming language.
A programming language should both provide means to describe primitive data and procedures
and means to combine and abstract those into more complex ones.
The distinction between data and procedures is not that clear cut. In many programming
languages, procedures can be passed as data (to be applied to ``real'' data) and sometimes processed like
``ordinary'' data. Conversely ``ordinary'' data can be turned into procedures by an evaluation mechanism.
http://eglobiotraining.com
4. At first, programming is confusing because you have so much to understand
about codes that will enable to run a program. Programming has applications and
program development, the best example for this is the Internet bowser…
Programming is a creative process done by programmers to instruct a
computer on how to do a task. Fundamentally programs manipulate numbers and text.
These are the building blocks of all programs. Programming languages let you use them
in different ways, e.g adding numbers, etc… or storing data on disk for later retrieval.
http://eglobiotraining.com
5. You have to consider languages to run or write your own program, most
demanded language in programming is the DEV C++ (a full-featured Integrated Development
Environment (IDE)).
C++ is one of the most used programming languages in the world. Also known as
"C with Classes".
New to programming or thinking about it? It might surprise you to know that there are many
programmers who program just for fun and it can lead to a job.
http://eglobiotraining.com
6. SWITCH CASE
Switch case statements are a substitute for
long if statements that compare a variable to several "integral" values
("integral" values are simply values that can be expressed as an
integer, such as the value of a char).
http://eglobiotraining.com
7. basic format for using switch case:
switch ( <variable> ) {
case this-value:
Code to execute if <variable> == this-value
break;
case that-value:
Code to execute if <variable> == that-value
break;
...
default:
Code to execute if <variable> does not equal the value following any of the cases
break;
}
The value of the variable given into switch is compared to the value following each of
the cases, and when one value matches the value of the variable, the computer
continues executing the program from that point.
http://eglobiotraining.com
8. The condition of a switch
statement is a value. The case says that if it
has the value of whatever is after that case
then do whatever follows the colon. The
break is used to break out of the case
http://eglobiotraining.com
9. “Break” is a keyword that breaks out of
the code block, usually surrounded by braces, which it is in. In
this case, break prevents the program from falling through and
executing the code in all the other case statements.
http://eglobiotraining.com
10. The default case is optional, but it is wise to
include it as it handles any unexpected cases. Switch statements
serves as a simple way to write long if statements when the
requirements are met. Often it can be used to process input
from a user.
http://eglobiotraining.com
11. This shows how would you use a Switch in a Program
#include <iostream>
using namespace std;
void playgame()
{
cout << "Play game called";
}
void loadgame()
}
cout << "Load game called";
void playmultiplayer()
{
cout << "Play multiplayer game called";
}
int main()
{
int input;
cout<<"1. Play gamen";
cout<<"2. Load gamen";
cout<<"3. Play multiplayern";
cout<<"4. Exitn";
cout<<"Selection: "; cin>> input;
switch ( input ) {
case 1: // Note the colon, not a semicolon
playgame();
break;
case 2: // Note the colon, not a semicolon
loadgame();
break;
case 3: // Note the colon, not a semicolon
playmultiplayer();
break;
case 4: // Note the colon, not a semicolon
cout<<"Thank you for playing!n";
break;
default: // Note the colon, not a semicolon
cout<<"Error, bad input, quittingn";
break;
}
cin.get();
} http://eglobiotraining.com
12. That program will compile, but cannot be run until
the undefined functions are given bodies, but it serves as a model
(albeit simple) for processing input. If you do not understand this
then try mentally putting in if statements for the case statements. Default
simply skips out of the switch case construction and allows the program to terminate
naturally. If you do not like that, then you can make a loop around the
whole thing to have it wait for valid input. You could easily make a few
small functions if you wish to test the code.
http://eglobiotraining.com
13. LOOPING
Loops are used to repeat a block of code. Being
able to have your program repeatedly execute a block of code is one of
the most basic but useful tasks in programming -- many programs or
websites that produce extremely complex output (such as a message
board) are really only executing a single task many times.
http://eglobiotraining.com
14. (They may be executing a small number
of tasks, but in principle, to produce a list of messages only
requires repeating the operation of reading in some data
and displaying it.) Now, think about what this means: a loop
lets you write a very simple statement to produce a significantly greater
result simply by repetition.
http://eglobiotraining.com
15. One Caveat: before going further, you
should understand the concept of C++'s true and
false, because it will be necessary when working with loops
(the conditions are the same as with if statements).
Three types of Loops:
for, while, and do..
http://eglobiotraining.com
16. FOR
For ( variable initialization; condition; variable update ) {
Code to execute while the condition is true
}
http://eglobiotraining.com
17. The variable initialization allows you to either declare a variable and give it a
value or give a value to an already existing variable. Second, the condition tells the program that while
the conditional expression is true the loop should continue to repeat itself. The variable update section
is the easiest way for a for loop to handle changing of the variable. It is possible to do things like x++,
x = x + 10, or even x = random ( 5 ), and if you really wanted to, you could call other functions that
do nothing to the variable but still have a useful effect on the code.
Notice that a semicolon separates each of these sections, that is important. Also note
that every single one of the sections may be empty, though the semicolons still have to be there. If
the condition is empty, it is evaluated as true and the loop will repeat until something else
stops it.
http://eglobiotraining.com
18. Example:
#include <iostream>
using namespace std; // So the program can see cout and endl
int main()
{
// The loop goes while x < 10, and x increases by one every loop
for ( int x = 0; x < 10; x++ ) {
// Keep in mind that the loop condition checks
// the conditional statement before it loops again.
// consequently, when x equals 10 the loop breaks.
// x is updated before the condition is checked.
cout<< x <<endl;
}
cin.get();
}
This program is a very simple example of a for loop. x is set to zero, while x
is less than 10 it calls cout<< x <<endl; and it adds 1 to x until the
condition is met. Keep in mind also that the variable is incremented after
the code in the loop is run for the first time.
http://eglobiotraining.com
19. The basic structure:
WHILE
While ( condition ) { Code to execute while the condition is true }
The true represents a boolean expression which could be x == 1 or
while ( x != 7 ) (x does not equal 7). It can be any combination of
boolean statements that are legal. Even, (while x ==5 || v == 7)
which says execute the code while x equals five or while v equals 7.
Notice that a while loop is the same as a for loop without the initialization
and update sections. However, an empty condition is not legal for a
while loop as it is with a for loop.
http://eglobiotraining.com
20. Example:
#include <iostream>
using namespace std; // So we can see cout and endl
int main()
{
int x = 0; // Don't forget to declare variables
while ( x < 10 ) { // While x is less than 10
cout<< x <<endl;
x++; // Update x so the condition can be met eventually
}
cin.get();
}
The easiest way to think of the loop is that when it reaches the brace at the end it
jumps back up to the beginning of the loop, which checks the condition again and
decides whether to repeat the block another time, or stop and move to the next
statement after the block.
http://eglobiotraining.com
21. DO..WHILE
are useful for things that want to loop at least once.
The Structure:
do {
} while ( condition ) ;
http://eglobiotraining.com
22. Notice that the condition is tested at the end of the
block instead of the beginning, so the block will be executed at least
once. If the condition is true, we jump back to the beginning of the
block and execute it again. A do..while loop is basically a reversed
while loop. A while loop says "Loop while the condition is true, and
execute this block of code", a do..while loop says "Execute this block of
code, and loop while the condition is true".
http://eglobiotraining.com
23. Example:
#include <iostream>
using namespace std;
int main()
{
int x;
x = 0;
do {
// "Hello, world!" is printed at least one time
// even though the condition is false
cout<<"Hello, world!n";
} while ( x != 0 );
cin.get();
}
Keep in mind that you must include a trailing semi-colon after the while in the
above example. A common error is to forget that a do..while loop must be
terminated with a semicolon (the other loops should not be terminated with a
semicolon, adding to the confusion). Notice that this loop will execute once,
because it automatically executes before checking the condition.
http://eglobiotraining.com
25. LOOPING STATEMENT 1
#include <iostream>
int main()
{
using namespace std;
// nSelection must be declared outside do/while loop
int nSelection;
do
{
cout << "Please make a selection: " << endl;
cout << "1) Addition" << endl;
cout << "2) Subtraction" << endl;
cout << "3) Multiplication" << endl;
cout << "4) Division" << endl;
cin >> nSelection;
} while (nSelection != 1 && nSelection != 2 &&
nSelection != 3 && nSelection != 4);
// do something with nSelection here
// such as a switch statement
return 0;
}
http://eglobiotraining.com
26. LOOPING STAEMENT 2
#include <iostream>
using namespace std;
int main()
{
int nSelection;
double var1, var2;
do
{
cout << "Please make a selection: " << endl;
cout << "1) Addition" << endl;
cout << "2) Subtraction" << endl;
cout << "3) Multiplication" << endl;
cout << "4) Division" << endl;
cin >> nSelection;
}
while (nSelection != 1 && nSelection != 2 &&
nSelection != 3 && nSelection != 4);
if (nSelection == 1)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1+var2) << endl;
}
http://eglobiotraining.com
27. LOOPING STATEMENT 3
if (nSelection == 2)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1-var2) << endl;
}
if (nSelection == 3)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1*var2) << endl;
}
if (nSelection == 4)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1/var2) << endl;
}
return 0;
}
http://eglobiotraining.com
28. LOOPING STATEMENT 3
#include <iostream>
using namespace std;
int main()
{
int nSelection;
double var1, var2;
while (1)
{
do
{
cout << "Please make a selection: " << endl;
cout << "1) Addition" << endl;
cout << "2) Subtraction" << endl;
cout << "3) Multiplication" << endl;
cout << "4) Division" << endl;
cout << "5) Exit" << endl;
cin >> nSelection;
} while (nSelection != 1 && nSelection != 2 &&
nSelection != 3 && nSelection != 4 &&
nSelection != 5);
if (nSelection == 1)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1+var2) << endl;
}
http://eglobiotraining.com
29. LOOPING STATEMENT 4
else if (nSelection == 2)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1-var2) << endl;
}
else if (nSelection == 3)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1*var2) << endl;
}
else if (nSelection == 4)
{
cout << "Please enter the first whole number ";
cin >> var1;
cout << "Please enter the second whole number ";
cin >> var2;
cout << "The result is " << (var1/var2) << endl;
}
else
{
return 0;
}
}
}
http://eglobiotraining.com
30. LOOPING STATEMENT 5
#include <iostream>
using namespace std; // So the program can see cout and endl
int main()
{
// The loop goes while x < 10, and x increases by one every loop
for ( int x = 0; x < 10; x++ ) {
// Keep in mind that the loop condition checks
// the conditional statement before it loops again.
// consequently, when x equals 10 the loop breaks.
// x is updated before the condition is checked.
cout<< x <<endl;
}
cin.get();
}
http://eglobiotraining.com
31. LOOPING STATEMENT 6
#include <iostream>
using namespace std;
int main()
{
int x;
x = 0;
do {
// "Hello, world!" is printed at least one time
// even though the condition is false
cout<<"Hello, world!n";
} while ( x != 0 );
cin.get();
}
http://eglobiotraining.com
32. LOOPING STATEMENT 7
#include <iostream>
using namespace std;
int main ()
{
int n;
cout << "Enter the starting number > ";
cin >> n;
while (n>0) {
cout << n << ", ";
--n;
}
cout << "FIRE!n";
return 0;
}
http://eglobiotraining.com
33. SWITCH CASE 1
SWITCH CASE
#include <iostream>
using namespace std;
int main ()
{
int score;
cout << "What was your score?";
cin >> score;
if (score <= 25)
{
cout << "nOuch, less than 25...!";
}
http://eglobiotraining.com
34. SWITCH CASE 2
else if (score <= 50)
{
cout << "nYou score aint great mate..";
}
else if (score <= 75)
{
cout << "nYour pretty good, wel done man!";
}
else if (score <= 100)
{
cout << "nYou got to the top!!!";
}
http://eglobiotraining.com
36. SWITCH CASE 4
#include <iostream>
using namespace std;
int main(){
cout << "Enter a number between 1 and 5!" << endl;
int number;
cin >> number;
if(number == 1){
cout << "one";
}
else if(number == 2){
cout << "two";
}
else if(number == 3){
cout << "three";
}
else if(number == 4){
cout << "four";
}
else if(number == 5){
cout << "five";
}
else{
cout << number << " is not between 1 and 5!";
}
cout << endl;
system("pause");
}
http://eglobiotraining.com
37. SWITCH CASE 5
#include <iostream>
using namespace std;
int main()
{
int price_before_discount, RM, dozen, total_price;
cout<< "How much is the price before discount for 1 dozen boxes of tissue?n";
cout<<"RM ";
cin>>price_before_discount;
cout<<"nn";
cout<< "How many dozen boxes of tissue you buy?n";
cin>>dozen;
cout<<"nn";
switch (dozen)
{
total_price = ((price_before_discount*dozen) * (95/100));
case '1': cout<< "Total price is RM ";
cout<<RM;
cout<<"nn";
break;
total_price = ((price_before_discount*dozen) * (88/100));
case '2': cout<< "Total price is RM ";
cout<<RM;
cout<<"nn";
break;
total_price = ((price_before_discount*dozen) * (75/100));
case '3': cout<< "Total price is RM ";
cout<<RM;
cout<<"nn";
break;
total_price = ((price_before_discount*dozen) * (60/100));
case '4' : cout<< "Total price is RM ";
cout<<RM;
cout<<"nn";
break;
total_price = ((price_before_discount*dozen) * (40/100));
default : cout<< "Total price is RM ";
cout<<RM;
cout<<"nn";
}
return 0;
}
http://eglobiotraining.com
38. SWITCH CASE 6
#include <stdlib.h>
#include <stdio.h>
int main(void) {
int n;
printf("Please enter a number: ");
scanf("%d", &n);
switch (n) {
case 1: {
printf("n is equal to 1!n");
break;
}
case 2: {
printf("n is equal to 2!n");
break;
}
case 3: {
printf("n is equal to 3!n");
break;
}
default: {
printf("n isn't equal to 1, 2, or 3.n");
break;
}
}
system("PAUSE");
return 0;
}
http://eglobiotraining.com
39. SWITCH CASE 7
#include <iostream>
using namespace std;
int main(void)
{
char grade;
cout << "Enter your grade: ";
cin >> grade;
switch (grade)
{
case 'A':
cout << "Your average must be between 90 - 100"
<< endl;
break;
case 'B':
cout << "Your average must be between 80 - 89"
<< endl;
break;
case 'C':
cout << "Your average must be between 70 - 79"
<< endl;
break;
case 'D':
cout << "Your average must be between 60 - 69"
<< endl;
break;
default:
cout << "Your average must be below 60" << endl;
}
return 0;
}
http://eglobiotraining.com
41. In this looping statement, I used “while” looping, and I choose to show MDAS
just as an example for the program to run. If logical Expression evaluates
to true, the statement executes. The logical Expression is reevaluated. The
body of the loop continues to execute until the logicalExpression is false
http://eglobiotraining.com
42. I have came up with this by just starting to write this code: #include
<iostream> and then enter the succeeding codes, compiled and run.
http://eglobiotraining.com
43. I noticed that sometimes if the program does not run, it is because some
braces are not included and I accidentally put braces on the same line and it
causes the program not to read its contents. Programming is
sensitive, when there is missing variable or braces or some words it does not
run.
http://eglobiotraining.com
44. When I learned that programming is very sensitive and at the same
time very detailed when it comes to entering codes, I make sure that it
is clear means that I put everything important codes in it so that the
program would run.
http://eglobiotraining.com
45. . So much codes that should be entered that even the spaces are needed
programming is very specific that whatever you have entered in to it you
should specify because when the statement is false it wouldn’t let you run the
program, I have experienced it before I arrived at this result
http://eglobiotraining.com
46. Because of so many experiences I had before this program run, I
found programming is also interesting for the more you are practicing to
make a program run, the more questions that came up in my mind and try
something that will fit to this or entering new codes to make matrix etc…
that I know is possible.
http://eglobiotraining.com
47. In this switch case missing out a break statement causes control to
fall through to the next case label. Switches can always be replaced by
nested if-else statements, but in some cases this may be more clumsy.
Each break statement terminates the enclosing switch statement. Control flow
continues with the first statement
http://eglobiotraining.com
48. Unlike if-then and if-then-else statements, the switch statement can
have a number of possible execution paths, A switch works with
the byte, short, char, and int primitive data types.
http://eglobiotraining.com
49. The switch statement evaluates its expression, then executes all
statements that follow the matching case label.
http://eglobiotraining.com
50. The switch statement can include any number
of case instances, but no two case constants within the same switch statement
can have the same value. Execution of the statement body begins at the
selected statement and proceeds until the jump-statement transfers control
out of the case body.
http://eglobiotraining.com
52. SUBMITTED TO:
P RO F. E R W I N G L O B I O
H T T P : / / E G L O B I O T R A I N I N G.
COM/
Submitted by:
Bulatao, Carlo June D.
BM10203
http://eglobiotraining.com