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.
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.
Function overloading in C++ allows defining multiple functions with the same name as long as they have different parameters. This enables functions to perform different tasks based on the types of arguments passed. An example demonstrates defining multiple area() functions, one taking a radius and the other taking length and breadth. Inline functions in C++ avoid function call overhead by expanding the function code at the call site instead of jumping to another location. Demonstrated with an inline mul() and div() example.
Functions in C allow programmers to package blocks of code that perform tasks. Functions make code reusable and easier to understand by separating code into modular units. A function has a name, list of arguments it takes, and code that is executed when the function is called. Functions can communicate between each other via parameters passed by value or by reference. Parameters passed by value are copied, so changes inside the function don't affect the original variable, while parameters passed by reference allow the function to modify the original variable. Functions can also call themselves recursively.
C++ is an object-oriented programming language that is an extension of C. It was developed in the early 1980s by Bjarne Stroustrup at Bell Labs. C++ supports concepts like inheritance, polymorphism, and encapsulation that make it suitable for large, complex programs. Inheritance allows classes to inherit properties from parent classes. Polymorphism is the ability to process objects of different types in the same way. Encapsulation combines data and functions that operate on that data within a single unit, hiding implementation details. File input/output in C++ can be handled through streams like ifstream for input and ofstream for output.
This document contains code examples demonstrating different C++ functions concepts including:
- Functions that take no arguments
- Calling functions multiple times from main()
- Passing arguments to functions
- Function prototypes and definitions
- Value and reference parameters
- Scoping rules for local and global variables
- Overloaded functions
- Default arguments in functions
The examples show how to define, call and pass parameters to functions in C++.
The document discusses loop control statements in C++. It describes the three main types of loops - for, while, and do-while loops. It provides examples of how a for loop works, including the initialization, test, and update expressions that control the loop execution. It also gives a sample program to calculate the sum of the first n positive integers using a for loop.
The document discusses loop control structures in C++. It explains the for, while, and do-while loops and provides examples. It also covers break, continue, return, and goto statements used to control program flow in loops.
The document discusses functions and recursion in C programming. It provides examples of different types of functions like void, float, int functions. It demonstrates simple functions with no parameters, functions that return values, and functions with parameters. It also explains recursion with examples of calculating factorials and Fibonacci series recursively. Finally, it discusses other function related concepts like function prototypes, scope of variables, and pre-defined math functions in C.
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
油
The document discusses C++ functions. It defines what a function is and describes the different types of C++ functions including standard and user-defined functions. It explains the structure of C++ functions including the function header, signature, and body. It provides examples of defining, declaring, implementing and calling functions. It also discusses topics like function parameters, scope of variables, inline functions, and building libraries.
Rust is a systems programming language that offers performance comparable to C and C++ with memory safety and thread safety. It uses a borrow checker to enforce rules around ownership, borrowing, and lifetimes that prevent common bugs like use of dangling pointers and data races. Rust also supports features like generics, pattern matching, and idioms that improve productivity without sacrificing performance.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
following is work on Advance Python part 1 Functional Programming in Python
for code and more details plz do visit
https://lnkd.in/dnQF95z
for more free study material and Projects follow on
Github
https://lnkd.in/gYKtuB3
LinkedIn
https://lnkd.in/daSvf_P
#python #datascience #programming #machinelearning #github #deeplearning #coding #developer #projects #work #developers #linkedin #google #amazonindia#IBM
Functions in C allow programmers to organize code into self-contained blocks that perform specific tasks. A function is defined with a name and can accept parameters. The main() function is where program execution begins. Several examples are provided that demonstrate defining and calling functions to perform tasks like addition, incrementing values, and displaying output. Functions can access variables in their own scope as well as variables passed into them as parameters.
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
油
Introduction to looping, for loop. while loop, do loop jump statements, entry controlled vs exit controlled loop, algorithm and flowchart of loops, factorial of a number
The document discusses the basics of functions in Python, including what a function is, the advantages of using functions, how to define and call functions, and how to use parameters, return values, global variables, default arguments, keyword arguments, and docstrings when working with functions. Key points covered include how functions allow code reuse and decomposition of complex problems, how to define a function using the def keyword, how to call a defined function by name, and how docstrings provide documentation for functions and other objects.
The document discusses different types of storage classes in C++ that determine the lifetime and scope of variables:
1. Local variables are defined inside functions and have scope limited to that function. They are destroyed when the function exits.
2. Global variables are defined outside all functions and have scope in the entire program. They are destroyed when the program ends.
3. Static local variables are local variables that retain their value between function calls. Register variables are local variables stored in processor registers for faster access.
4. Thread local storage allows defining variables that are local to each thread and retain their values similar to static variables. The document provides examples to illustrate local, global, and static variables.
C++ is an object-oriented programming language that was created as an extension of C programming language. It was created by Bjarne Stroustrup in 1979 at Bell Labs. Some key differences between C and C++ include C++ supporting object-oriented programming concepts like classes, inheritance and polymorphism, while C is a procedural language. Pointers and references are commonly used in C++ to pass arguments to functions by reference rather than by value. Arrays and functions are also important elements of C++ programs.
Pointer variables store memory addresses and can be used to indirectly access other variables. Pointers allow values to be passed by reference into functions rather than by value. Arrays can be accessed using pointers by treating the array name as a pointer to its first element. Dynamic memory allocation with new/delete operators allows pointers to reference variables in heap memory.
The document discusses functions in C++. It defines a function as a block of code that performs a specific task. There are two types of functions: built-in functions provided by the language and user-defined functions created by the programmer. The components of a function include the function header, body, parameters, return type, local variables, and return statement. Functions can pass arguments either by value or by reference. The document provides examples of built-in and user-defined functions as well as examples demonstrating call by value and call by reference.
Sometimes you see code that is perfectly OK according to the definition of the language, but which is flawed because it breaks too many established idioms and conventions. On the other hand, a solid piece of code is something that looks like it is written by an experienced person who cares about professionalism in programming.
A presentation at Norwegian Developer Conference 2010
The document discusses different types of loops in C++ including while, do-while, for, and switch-case statements. It provides examples of using each loop or statement to repeat operations a certain number of times or while a condition is met. Key examples include a countdown loop using while, calculating factorials with for, and a calculator program using switch-case to perform math operations.
Functions allow code to be reused by defining formulas that can be called from different parts of a program. Functions take in inputs, perform operations, and return outputs. They are defined outside of the main body with a function prototype, and can be called multiple times from within main or other functions. This document demonstrates how to define a FindMax function that takes in two numbers, compares them, and returns the maximum number. It shows function prototypes, defining the function outside of main, and calling the function from within main to find the maximum of two user-input numbers.
The document discusses several key aspects of programming in C language including:
- C language uses a compiler to translate source code into executable binary code.
- Common elements of a C program include header files, main function, use of printf and scanf functions.
- Basic data types in C include integer, float, character, and other numeric types. Variables of these types can be declared and used in C programs.
Lecture#7 Call by value and reference in c++NUST Stuff
油
This document discusses references and reference parameters in C++. It explains that call by reference allows a function to directly access and modify the original argument, unlike call by value where only a copy is passed. A reference parameter creates an alias for the argument, allowing changes to affect the original. The document provides examples demonstrating pass by value versus pass by reference using reference parameters, and also covers default arguments, reference initialization requirements, and function overloading.
This document provides an overview of C++ programming concepts including:
1. C++ programs consist of functions, with every program containing a main() function. Functions contain declarations, statements, comments, and can call libraries.
2. Variables must be declared with a type and can be used to store values. C++ supports integer, floating point, character, and other variable types.
3. C++ allows selection and decision making using if/else statements, switch statements, logical operators, and loops like while and for. Operators allow comparisons and boolean evaluations.
This document discusses algorithms and programming. It begins by defining an algorithm as a finite set of steps to solve a problem. It provides examples of algorithms to find the average of test scores and divide two numbers. The document discusses characteristics of algorithms like inputs, outputs, definiteness, finiteness, and effectiveness. It also covers tools for designing algorithms like flowcharts and pseudocode. The document then discusses programming, explaining how to analyze a problem, design a solution, code it, test it, and evaluate it. It provides tips for writing clear, well-structured programs.
The document discusses loop control statements in C++. It describes the three main types of loops - for, while, and do-while loops. It provides examples of how a for loop works, including the initialization, test, and update expressions that control the loop execution. It also gives a sample program to calculate the sum of the first n positive integers using a for loop.
The document discusses loop control structures in C++. It explains the for, while, and do-while loops and provides examples. It also covers break, continue, return, and goto statements used to control program flow in loops.
The document discusses functions and recursion in C programming. It provides examples of different types of functions like void, float, int functions. It demonstrates simple functions with no parameters, functions that return values, and functions with parameters. It also explains recursion with examples of calculating factorials and Fibonacci series recursively. Finally, it discusses other function related concepts like function prototypes, scope of variables, and pre-defined math functions in C.
C++ functions presentation by DHEERAJ KATARIADheeraj Kataria
油
The document discusses C++ functions. It defines what a function is and describes the different types of C++ functions including standard and user-defined functions. It explains the structure of C++ functions including the function header, signature, and body. It provides examples of defining, declaring, implementing and calling functions. It also discusses topics like function parameters, scope of variables, inline functions, and building libraries.
Rust is a systems programming language that offers performance comparable to C and C++ with memory safety and thread safety. It uses a borrow checker to enforce rules around ownership, borrowing, and lifetimes that prevent common bugs like use of dangling pointers and data races. Rust also supports features like generics, pattern matching, and idioms that improve productivity without sacrificing performance.
This document provides an outline and overview of functions in C++. It discusses:
- The definition of a function as a block of code that performs a specific task and can be called from other parts of the program.
- The standard library that is included in C++ and provides useful tools like containers, iterators, algorithms and more.
- The parts of a function definition including the return type, name, parameters, and body.
- How to declare functions, call functions by passing arguments, and how arguments are handled.
- Scope rules for local and global variables as they relate to functions.
following is work on Advance Python part 1 Functional Programming in Python
for code and more details plz do visit
https://lnkd.in/dnQF95z
for more free study material and Projects follow on
Github
https://lnkd.in/gYKtuB3
LinkedIn
https://lnkd.in/daSvf_P
#python #datascience #programming #machinelearning #github #deeplearning #coding #developer #projects #work #developers #linkedin #google #amazonindia#IBM
Functions in C allow programmers to organize code into self-contained blocks that perform specific tasks. A function is defined with a name and can accept parameters. The main() function is where program execution begins. Several examples are provided that demonstrate defining and calling functions to perform tasks like addition, incrementing values, and displaying output. Functions can access variables in their own scope as well as variables passed into them as parameters.
Iterative control structures, looping, types of loops, loop workingNeeru Mittal
油
Introduction to looping, for loop. while loop, do loop jump statements, entry controlled vs exit controlled loop, algorithm and flowchart of loops, factorial of a number
The document discusses the basics of functions in Python, including what a function is, the advantages of using functions, how to define and call functions, and how to use parameters, return values, global variables, default arguments, keyword arguments, and docstrings when working with functions. Key points covered include how functions allow code reuse and decomposition of complex problems, how to define a function using the def keyword, how to call a defined function by name, and how docstrings provide documentation for functions and other objects.
The document discusses different types of storage classes in C++ that determine the lifetime and scope of variables:
1. Local variables are defined inside functions and have scope limited to that function. They are destroyed when the function exits.
2. Global variables are defined outside all functions and have scope in the entire program. They are destroyed when the program ends.
3. Static local variables are local variables that retain their value between function calls. Register variables are local variables stored in processor registers for faster access.
4. Thread local storage allows defining variables that are local to each thread and retain their values similar to static variables. The document provides examples to illustrate local, global, and static variables.
C++ is an object-oriented programming language that was created as an extension of C programming language. It was created by Bjarne Stroustrup in 1979 at Bell Labs. Some key differences between C and C++ include C++ supporting object-oriented programming concepts like classes, inheritance and polymorphism, while C is a procedural language. Pointers and references are commonly used in C++ to pass arguments to functions by reference rather than by value. Arrays and functions are also important elements of C++ programs.
Pointer variables store memory addresses and can be used to indirectly access other variables. Pointers allow values to be passed by reference into functions rather than by value. Arrays can be accessed using pointers by treating the array name as a pointer to its first element. Dynamic memory allocation with new/delete operators allows pointers to reference variables in heap memory.
The document discusses functions in C++. It defines a function as a block of code that performs a specific task. There are two types of functions: built-in functions provided by the language and user-defined functions created by the programmer. The components of a function include the function header, body, parameters, return type, local variables, and return statement. Functions can pass arguments either by value or by reference. The document provides examples of built-in and user-defined functions as well as examples demonstrating call by value and call by reference.
Sometimes you see code that is perfectly OK according to the definition of the language, but which is flawed because it breaks too many established idioms and conventions. On the other hand, a solid piece of code is something that looks like it is written by an experienced person who cares about professionalism in programming.
A presentation at Norwegian Developer Conference 2010
The document discusses different types of loops in C++ including while, do-while, for, and switch-case statements. It provides examples of using each loop or statement to repeat operations a certain number of times or while a condition is met. Key examples include a countdown loop using while, calculating factorials with for, and a calculator program using switch-case to perform math operations.
Functions allow code to be reused by defining formulas that can be called from different parts of a program. Functions take in inputs, perform operations, and return outputs. They are defined outside of the main body with a function prototype, and can be called multiple times from within main or other functions. This document demonstrates how to define a FindMax function that takes in two numbers, compares them, and returns the maximum number. It shows function prototypes, defining the function outside of main, and calling the function from within main to find the maximum of two user-input numbers.
The document discusses several key aspects of programming in C language including:
- C language uses a compiler to translate source code into executable binary code.
- Common elements of a C program include header files, main function, use of printf and scanf functions.
- Basic data types in C include integer, float, character, and other numeric types. Variables of these types can be declared and used in C programs.
Lecture#7 Call by value and reference in c++NUST Stuff
油
This document discusses references and reference parameters in C++. It explains that call by reference allows a function to directly access and modify the original argument, unlike call by value where only a copy is passed. A reference parameter creates an alias for the argument, allowing changes to affect the original. The document provides examples demonstrating pass by value versus pass by reference using reference parameters, and also covers default arguments, reference initialization requirements, and function overloading.
This document provides an overview of C++ programming concepts including:
1. C++ programs consist of functions, with every program containing a main() function. Functions contain declarations, statements, comments, and can call libraries.
2. Variables must be declared with a type and can be used to store values. C++ supports integer, floating point, character, and other variable types.
3. C++ allows selection and decision making using if/else statements, switch statements, logical operators, and loops like while and for. Operators allow comparisons and boolean evaluations.
This document discusses algorithms and programming. It begins by defining an algorithm as a finite set of steps to solve a problem. It provides examples of algorithms to find the average of test scores and divide two numbers. The document discusses characteristics of algorithms like inputs, outputs, definiteness, finiteness, and effectiveness. It also covers tools for designing algorithms like flowcharts and pseudocode. The document then discusses programming, explaining how to analyze a problem, design a solution, code it, test it, and evaluate it. It provides tips for writing clear, well-structured programs.
The document summarizes different types of computers:
1) It describes analog computers, digital computers, and hybrid computers. Analog computers use continuous signals and outputs while digital computers use discrete signals and counts.
2) It then discusses various types of digital computers based on size and power - microcomputers, mini computers, mainframe computers, supercomputers. Microcomputers are smallest while mainframes are largest and most powerful.
3) The document concludes by mentioning that hybrid computers combine features of analog and digital computers and lists some examples of personal computing devices.
This document provides an introduction and overview for a course on programming in C++. It discusses the goals of the course, which are to teach programming principles and the C++ language. Students will learn essential concepts like variables, data types, functions, and arrays. They will write increasingly complex programs and develop good programming style. The course will be assessed through quizzes, exams, and class projects. Topics to be covered include variables, input/output, control flow, arrays, pointers, strings, and file I/O. Good programming practices like readability, simplicity, and avoiding reinventing solutions are emphasized.
This document provides an introduction to C++ for Java developers. It discusses the C++ standard and standard library, which includes containers, strings, input/output streams, and other functionality. It also covers installing compilers like GCC, compiling and running simple C++ programs, code style, using Makefiles, and includes examples of basic C++ syntax like output, input, datatypes, and strings.
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.
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.
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.
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.
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.
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.
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.
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 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.
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 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.
The document discusses various control structures and functions used in Arduino programming including decision making structures like if, else if, else statements and switch case statements. It also covers different types of loops like while, do-while and for loops that allow repeating blocks of code. Functions are described as reusable blocks of code that perform tasks and help organize a program. Strings can be implemented as character arrays or using the String class, and various string functions are provided to manipulate and work with strings.
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.
Loop constructs allow sections of code to repeat a specified number of times. There are three main types of loops in C++:
1. For loops use a counter variable that is initialized, tested against a condition on each iteration, and incremented/decremented until false.
2. While loops continuously execute a block of code as long as a condition is true.
3. Do-while loops are similar but execute the block of code once before checking the condition, ensuring it runs at least once.
Loops allow code to be executed repeatedly. The main loop types are while, for, and do-while loops. While and do-while loops test the condition at the beginning or end of the loop respectively. For loops allow code to be executed a specific number of times. Loops can be nested by placing one loop inside another. Break and continue statements control the flow of loops. Break exits the current loop while continue skips to the next iteration. Though goto can provide unconditional jumps, its use is discouraged due to reducing code readability.
Loop control statements in C are used to repeatedly execute a block of code while or until a given condition is true. There are three main types of loop control statements in C: for, while, and do-while loops. The for loop allows executing a block of code a specific number of times. The while loop repeatedly executes the block as long as the condition is true. The do-while loop is similar to the while loop, but it will always execute the block at least once even if the condition is false.
Control structures in C++ allow programs to conditionally execute code or repeat code in loops. The if/else statement executes code based on a condition being true or false. A while loop repeats a statement as long as a condition is true. A do/while loop repeats a statement first, then checks a condition to repeat. A for loop initializes a counter, checks a condition, and increments the counter on each iteration while the condition is true. Break and continue can prematurely exit or skip iterations in loops.
The document is a PowerPoint presentation about looping statements in programming. It contains code examples of do-while loops in C++. The do-while loop ensures that the code block inside the loop executes at least once before checking the loop condition. One example shows a do-while loop that displays a menu to the user and waits for a valid selection. The variable used in the loop condition must be declared outside the do block to be accessible after the block executes.
The document contains presentations on various looping statements in programming like while, do-while and for loops. It includes examples of using these loops to iterate through a menu of options until a valid selection is made, print a countdown until a condition is met, and explanations of how each loop type works. Code snippets with explanations are provided to demonstrate the different looping statements and switch-case structure.
2. Looping in Programming
Loops in programming are used to repeat a block of code. Being
able to have your programming repeatedly execute a block of code
is one of the most basic but useful tasks in programming -- many
programming programs or programming websites that produce
extremely complex output are really only executing a single task
many times. A loop in programming lets you write a very simple
statement to produce a significantly greater result simply by
repetition.
http://eglobiotraining.com.
3. For Loop
For Loop is the most useful type in loop programming.
The syntax for for loop is :
for ( variable initialization; condition; variable update ) {
Code to execute while the condition is true
}
The variable initialization in for loop 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 programming that while the
conditional expression in programming 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 in programming
.
http://eglobiotraining.com.
4. Example of For Loop
The code for the example of for loop is:
#include <iostream>
using namespace std;
int main()
{
for ( int x = 0; x < 10; x++ ) {
cout<< x <<endl;
}
cin.get();
}
http://eglobiotraining.com.
7. Explanation of the for loop
This programming is a 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 in the programming is met.
http://eglobiotraining.com.
8. Example of for loop
#include <iostream>
using油namespace std;
int油main() {
double油f; // holds the length in feet
double油m; // holds the conversion to meters
int油counter;
counter = 0;
for(f = 1.0; f <= 100.0; f++) {
m = f / 3.28; // convert to meters
cout << f << " feet is " << m << " meters.n";
counter++;
// every 10th line, print a blank line
if(counter == 10) {
cout << "n"; // output a blank line
counter = 0; // reset the line counter
} http://eglobiotraining.com.
14. Explanation of For Loop
The output of the above example showed
tha conversion table of length (feet to
meters).
http://eglobiotraining.com.
15. While Loop
WHILE loops programming are very simple. The basic structure of the
while loop is:
while ( condition ) { Code to execute while the condition is true } The
true represents a boolean expression in programming which could
be x == 1 or while ( x != 7 ) (x does not equal 7). It can be any
combination of boolean statements in programming 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 in
programming is the same as a for loop without the initialization and
update sections. However, an empty condition in programming is
not legal for a while loop as it is with a for loop.
http://eglobiotraining.com.
16. Example of While Loop :
#include <iostream>
using namespace std;
int main()
{
int x = 0;
while ( x < 10 ) {
cout<< x <<endl;
x++;
}
cin.get();
} http://eglobiotraining.com.
18. Output of the While Loop
http://eglobiotraining.com.
19. Expalanation for While :
This While is simple, but it is longer than the
above FOR loop programming. The easiest
way to think of the loop programming is that
when it reaches the brace at the end it jumps
back up to the beginning of the loop
programming, 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.
20. Do..While
DO..WHILE loops are useful for programming that want to loop at least
once. The structure is:
do {
} while ( condition );
Notice that the condition in the programming is tested at the end of the
block instead of the beginning, so the block will be executed in the
programming at least once. If the condition is true, we jump back to
the beginning of the block in the programming and execute it again.
A do..while loop is basically a reversed while loop programming. A
while loop programming says "Loop while the condition is true, and
execute this block of code", a do..while loop programming says
"Execute this block of code, and loop while the condition is true".
http://eglobiotraining.com.
21. Example of Do..While
#include <iostream>
using namespace std;
int main()
{
int x;
x = 0;
do {
cout<<Programming is Funn";
} while ( x != 0 );
cin.get();
}
http://eglobiotraining.com.
24. Explanation of Do..While
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 in C++ programming 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. Infinite loop
A loop becomes infinite loop in C++
programming if a condition never
becomes false. The for loop is traditionally
used for this purpose. Since none of the
three expressions that form the for loop
are required, you can make an endless
loop by leaving the conditional expression
empty.
http://eglobiotraining.com.
26. Example of Infinite Loop
#include <iostream>
using namespace std;
int main ()
{
for( ; ; )
{ printf("This loop will run forever.n"); }
return 0;
}
http://eglobiotraining.com.
28. Output of the Infinite Loop
http://eglobiotraining.com.
29. Switch Case programming
The switch statement is used in C++
programming for testing if a variable is
equal to one of a set of values. The
variable must be an integer, i.e. integral or
non-fractional. The programmer can
specify the actions taken for each case of
the possible values the variable can have.
http://eglobiotraining.com.
30. Example of Switch Case
#include <stdlib.h>
statement
#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.
41. Explanation
The Switch case program shown above
will ask for a number and a letter an
distinguish if it is available in the program.
http://eglobiotraining.com.
42. DEV C++ PROGRAMMING
Submitted By: Baylon, Gerone Vianca Q.
http://www.slideshare.net/upload?
from_source=loggedin_newsfeed
Submitted To: Mr. Erwin Globio
http://eglobiotraining.com/
http://eglobiotraining.com.