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.
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.
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 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.
The document discusses different types of nested loops in programming. It explains nested while loops, do-while loops, and nested for loops. For nested while loops, the inner loop must start after the outer loop and end before the outer loop. An example prints a series using nested while loops. Do-while loops execute the loop statement once before checking the condition. An example uses do-while to check if a number is positive or negative. Nested for loops can contain another for loop in its body, as long as the inner loop variable has a different name. An example prints a series using nested for loops.
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.
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.
1) The document provides an introduction to programming concepts like flow charts, libraries, variables, data types, inputs/outputs, and operators.
2) Control structures like if/else, switch, and different types of loops (for, while, do-while) are explained with examples.
3) An assignment is given to write a calculator program that takes two numbers from the user, an operation to perform, performs the calculation, and allows the user to choose another operation or exit.
Loops allow sections of code to repeat a certain number of times. There are three main types of loops in C++:
1. The for loop repeats until a test condition is false, and includes initialization, condition, and increment expressions.
2. The while loop repeats until a condition is false, without a fixed number of iterations.
3. The do-while loop guarantees running the loop body at least once before checking the condition, unlike the while loop which may not run if the condition is false.
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.
Iterative structures, also known as loops, repeat sections of code and are used for tasks like calculating multiple values, computing iterative results, printing tables of data, and processing large amounts of input or array data. The three types of loops in C++ are the while loop, do-while loop, and for loop, each with different test conditions to control the loop execution. Loops can also be nested within each other to perform multiple iterations or to loop through multi-dimensional data structures.
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.
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 provides information on control structures in C++ including relational operators, loops, and decisions. It discusses relational operators like ==, <, > that compare values and return true or false. It describes the three types of loops in C++ - for, while, and do-while loops. The for loop executes a fixed number of times based on initialization, test, and increment expressions. The while loop repeats while a test condition is true. The do-while loop executes the body at least once and then repeats while the test condition is true. The document also covers the if statement for simple conditions and if-else for alternative paths, and provides code examples to demonstrate each control structure.
The document discusses the programming language C. It provides a brief history of C including its creation in 1972 by Dennis Ritchie and key developments like ANSI C. It also defines C as a high-level, general purpose language ideal for developing firmware and portable applications. Originally intended for writing system software, C was developed for the Unix Operating System. The document then discusses some basic C concepts like variables, logical operators, and control flow statements like if-else, switch, while loops, do-while loops, and for loops.
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Ìý
Nested Loops and Jumping Statements(Loop Control Statements), Goto statement in C, Return Statement in C Exit statement in C, For Loops with Nested Loops, While Loop with Nested Loop, Do-While Loop with Nested Loops, Break Statement, Continue Statement : visit us at : www.rozyph.com
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.
what are loop in general
what is loop in c language
uses of loop in c language
types of loop in c language
program of loop in c language
syantax of loop in c language
This document discusses the appeal of Go for C++ developers and how some key Go features are implemented under the hood. It notes that concurrent I/O programming in C++ can be complicated, verbose, and fragile, whereas Go's goroutines, netpoller, and channels make concurrency easier. Goroutines use fast context switching via thread local storage and assembly code. The netpoller leverages OS syscalls like epoll to unpark goroutines only when I/O is available. Channels use lock-free operations and fast mutexes to efficiently pass data between goroutines.
The document discusses different types of loops in C programming: for loops, while loops, and do-while loops. For loops allow initialization of a variable, specify a condition, and how to increment the variable. While loops repeatedly execute code as long as a condition is true. Do-while loops are similar but check the condition at the bottom of the loop, so the code executes at least once. Examples of each loop type are provided.
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
This document discusses decision and loop control in C programming. It covers if, if-else, conditional operators, relational operators, logical operators, the conditional operator (? :) and various loops including while, do-while and for loops. Examples are provided to demonstrate the use of if/else, logical operators, conditional operators and while, do-while loops. Flowcharts are also included to illustrate program flow. The document is presented by Vinay Arora and covers basic conditional and loop control structures in C.
The document discusses various looping constructs in C++ including while, do-while, and for loops. It provides examples of using counters, sentinels, nested loops, break, continue, and running totals with loops. Key points covered include the differences between pretest and posttest loops, using loops for input validation, and tips for writing good test data when testing programs.
Go uses goroutines and channels for concurrency. Goroutines are lightweight threads that communicate through channels, which are typed queues that allow synchronous message passing. Channels can be used to synchronize access to shared memory, allowing both shared memory and message passing for concurrency. The language is designed for scalable fine-grained concurrency but further improvements are still needed, especially to the goroutine scheduler.
The document contains code snippets and descriptions for various C++ programs, including:
1) An abstract class example with Shape as the base class and Rectangle and Triangle as derived classes, demonstrating polymorphism.
2) A program that counts the words in a text by getting user input and parsing for whitespace.
3) An Armstrong number checker that determines if a number is an Armstrong number based on the sum of its digits.
4) Various other examples like binary search, complex number arithmetic, stacks, inheritance, and converting between Celsius and Fahrenheit temperatures.
Automotive electrical and electromechanical system designSayed Abbas
Ìý
This document discusses the challenges of designing automotive electrical and electromechanical systems. It addresses multi-domain, multi-level, and multi-organizational design challenges. It promotes an integrated design environment to enable modeling of different domains, accuracy levels, and organizational interactions. Libraries of automotive-specific components are described to support electrical, hydraulic, and power system modeling.
1) The document provides an introduction to programming concepts like flow charts, libraries, variables, data types, inputs/outputs, and operators.
2) Control structures like if/else, switch, and different types of loops (for, while, do-while) are explained with examples.
3) An assignment is given to write a calculator program that takes two numbers from the user, an operation to perform, performs the calculation, and allows the user to choose another operation or exit.
Loops allow sections of code to repeat a certain number of times. There are three main types of loops in C++:
1. The for loop repeats until a test condition is false, and includes initialization, condition, and increment expressions.
2. The while loop repeats until a condition is false, without a fixed number of iterations.
3. The do-while loop guarantees running the loop body at least once before checking the condition, unlike the while loop which may not run if the condition is false.
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.
Iterative structures, also known as loops, repeat sections of code and are used for tasks like calculating multiple values, computing iterative results, printing tables of data, and processing large amounts of input or array data. The three types of loops in C++ are the while loop, do-while loop, and for loop, each with different test conditions to control the loop execution. Loops can also be nested within each other to perform multiple iterations or to loop through multi-dimensional data structures.
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.
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 provides information on control structures in C++ including relational operators, loops, and decisions. It discusses relational operators like ==, <, > that compare values and return true or false. It describes the three types of loops in C++ - for, while, and do-while loops. The for loop executes a fixed number of times based on initialization, test, and increment expressions. The while loop repeats while a test condition is true. The do-while loop executes the body at least once and then repeats while the test condition is true. The document also covers the if statement for simple conditions and if-else for alternative paths, and provides code examples to demonstrate each control structure.
The document discusses the programming language C. It provides a brief history of C including its creation in 1972 by Dennis Ritchie and key developments like ANSI C. It also defines C as a high-level, general purpose language ideal for developing firmware and portable applications. Originally intended for writing system software, C was developed for the Unix Operating System. The document then discusses some basic C concepts like variables, logical operators, and control flow statements like if-else, switch, while loops, do-while loops, and for loops.
C lecture 4 nested loops and jumping statements slideshareGagan Deep
Ìý
Nested Loops and Jumping Statements(Loop Control Statements), Goto statement in C, Return Statement in C Exit statement in C, For Loops with Nested Loops, While Loop with Nested Loop, Do-While Loop with Nested Loops, Break Statement, Continue Statement : visit us at : www.rozyph.com
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.
what are loop in general
what is loop in c language
uses of loop in c language
types of loop in c language
program of loop in c language
syantax of loop in c language
This document discusses the appeal of Go for C++ developers and how some key Go features are implemented under the hood. It notes that concurrent I/O programming in C++ can be complicated, verbose, and fragile, whereas Go's goroutines, netpoller, and channels make concurrency easier. Goroutines use fast context switching via thread local storage and assembly code. The netpoller leverages OS syscalls like epoll to unpark goroutines only when I/O is available. Channels use lock-free operations and fast mutexes to efficiently pass data between goroutines.
The document discusses different types of loops in C programming: for loops, while loops, and do-while loops. For loops allow initialization of a variable, specify a condition, and how to increment the variable. While loops repeatedly execute code as long as a condition is true. Do-while loops are similar but check the condition at the bottom of the loop, so the code executes at least once. Examples of each loop type are provided.
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
This document discusses decision and loop control in C programming. It covers if, if-else, conditional operators, relational operators, logical operators, the conditional operator (? :) and various loops including while, do-while and for loops. Examples are provided to demonstrate the use of if/else, logical operators, conditional operators and while, do-while loops. Flowcharts are also included to illustrate program flow. The document is presented by Vinay Arora and covers basic conditional and loop control structures in C.
The document discusses various looping constructs in C++ including while, do-while, and for loops. It provides examples of using counters, sentinels, nested loops, break, continue, and running totals with loops. Key points covered include the differences between pretest and posttest loops, using loops for input validation, and tips for writing good test data when testing programs.
Go uses goroutines and channels for concurrency. Goroutines are lightweight threads that communicate through channels, which are typed queues that allow synchronous message passing. Channels can be used to synchronize access to shared memory, allowing both shared memory and message passing for concurrency. The language is designed for scalable fine-grained concurrency but further improvements are still needed, especially to the goroutine scheduler.
The document contains code snippets and descriptions for various C++ programs, including:
1) An abstract class example with Shape as the base class and Rectangle and Triangle as derived classes, demonstrating polymorphism.
2) A program that counts the words in a text by getting user input and parsing for whitespace.
3) An Armstrong number checker that determines if a number is an Armstrong number based on the sum of its digits.
4) Various other examples like binary search, complex number arithmetic, stacks, inheritance, and converting between Celsius and Fahrenheit temperatures.
Automotive electrical and electromechanical system designSayed Abbas
Ìý
This document discusses the challenges of designing automotive electrical and electromechanical systems. It addresses multi-domain, multi-level, and multi-organizational design challenges. It promotes an integrated design environment to enable modeling of different domains, accuracy levels, and organizational interactions. Libraries of automotive-specific components are described to support electrical, hydraulic, and power system modeling.
An introduction to pointers and references in C++ (with elements of C++11 and C++14). The presentation introduces the readers to the concepts of pointers and references through the pragmatic need of writing a swap function between integers. Generic programming notions (e.g., type constructors) are adopted when useful for the explanation.
Pratik Bakane C++ programs...............This are programs desingedby sy diploma student from Governement Polytecnic Thane.....programsare very easy alongwith coding andscreen shot of the output
Pratik Bakane C++ programs...............This are programs desingedby sy diploma student from Governement Polytecnic Thane.....programsare very easy alongwith coding andscreen shot of the output
The document lists the addresses and values of several variables, including var1, var2, var, and elements of the var array. It shows the address and value of individual variables like var and ip, as well as the addresses and values of elements in the var array both before and after some change to the array.
In this presentation, Adrian Hunt, Pre-Sales Consultant at PRQA explains how to achieve ISO 26262 Compliance with our static analysis tools QA·C and QA·C++.
This document discusses pointers in C++. It defines pointers as variables that store memory addresses and can be used to access and manipulate data at those addresses. It explains how to declare and initialize pointers, including pointer to pointer declarations. It discusses using pointers as function arguments and dynamic memory allocation using pointers with the new and delete operators. Pointers allow referencing variables indirectly and allocating memory dynamically at runtime.
A pointer is a variable that stores the memory address of another variable. Pointers hold addresses, while regular variables hold values. Computer memory is divided into sequentially numbered locations, with each variable assigned a unique address. Pointers allow manipulation of memory at a low level, making C++ suitable for embedded and real-time applications. Declaring a pointer simply requires specifying its type, like int*, and it reserves memory to hold an address. Pointers must be initialized, like int* pointer = 0, to avoid being "wild" pointers pointing to unknown memory. The address operator & returns a variable's address, which can be stored in a pointer.
Pointer is a variable that stores the memory address of another variable. It allows dynamic memory allocation and access of memory locations. There are three ways to pass arguments to functions in C++ - pass by value, pass by reference, and pass by pointer. Pass by value copies the value, pass by reference copies the address, and pass by pointer passes the address of the argument. Pointers can also point to arrays or strings to access elements. Arrays of pointers can store multiple strings. References are alternative names for existing variables and any changes made using the reference affect the original variable. Functions can return pointers or references.
This document discusses pointers in C++. It defines pointers as variables that store memory addresses and uses the address of (&) and indirection/dereference (*) operators. It provides several examples demonstrating how to declare pointer variables, assign the addresses of non-pointer variables to pointers, and use pointers to access and modify variable values indirectly through memory addresses. Key points covered include declaring pointer data types, assigning addresses to pointers using &, accessing values at addresses using *, and chaining pointers by assigning the address of one pointer to another pointer.
The document discusses arrays and pointers in C++. It covers:
- How to declare and initialize arrays
- Accessing array elements using subscripts
- Using parallel arrays when subscripts are not sequential numbers
- Special considerations for strings as arrays of characters
- Declaring pointer variables and using pointers to access array elements
- Potential issues with pointers like dangling references
Pratik Bakane C++ programs...............This are programs desingedby sy diploma student from Governement Polytecnic Thane.....programsare very easy alongwith coding andscreen shot of the output
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 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.
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.
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.
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 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.
This document provides information about loop statements in programming. It discusses the different parts of a loop, types of loops including while, for, and do-while loops. It also covers nested loops and jump statements like break and continue. Examples are given for each loop type. The document concludes with multiple choice and program-based questions as exercises.
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRKrishna Raj
Ìý
This document provides an overview of different types of loop statements in computer programming, including while loops, for loops, do-while loops, and nested loops. It also discusses jump statements like break, continue, goto, and exit that change the normal flow of loops. The key types of loops covered are while loops, which repeat a statement as long as a condition is true, for loops, which allow initialization of loop variables, testing a condition, and updating variables each iteration, and do-while loops, which first execute the statement and then check the condition.
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.
The document discusses switch case statements in C programming. It explains that switch case statements provide an alternative to long if-else statements by allowing a variable to be compared to multiple integer values. The program flow will continue at the case matching the variable's value. Break statements are used to exit each case block. A default case can handle any non-matching values. Examples are provided to demonstrate how switch case statements can be used to process user input and perform simple mathematical operations based on the input.
The document discusses different types of looping and conditional statements in programming languages.
1) A switch statement allows program execution to branch to different code blocks based on the value of a variable. It can improve clarity over repetitive if/else statements and may execute faster through compiler optimizations.
2) A for loop repeats a block of code a specified number of times. It is commonly used when the number of iterations is known beforehand.
3) If/else statements allow executing one block of code if a condition is true, and optionally executing another block if the condition is false. Else if blocks can test multiple conditions.
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.
Submitted To: Mr. Erwin Globio
http://eglobiotraining.com/
http://eglobiotraining.com.