Friday 10, February 2012
Welcome Guest, Register | Login  
      Home    |    Tutorials    |    Free Ebooks    |    Free Scripts    |    Articles    |    Blog     |    Forum    |    About Us    |    Contact Us

Looping in C++

Looping is probably one of the most important programming concepts in existence. There are so many applications of loops it would be impossible to list them all. To name a few though, things like parsing a string, trapping for errors, and animation. Also, since it will allow you to execute a block of code over and over, it saves time and typing. Now, depending on what kind of programming language you came from, loops might already be familiar to you, but if you've come from a low level programming language such as assembly or (god forbit) GWBasic, you are probably more familiar with jump or goto statements. Well, loops take into account all that lovely comparison crap you used to have to do before and puts it into one nice package. The easiest and most used of these loops is the for loop.

Syntax:
for ( variable initialization; condition; variable update ) {
  Code to execute while the condition is true
}

Example:
#include

using namespace std;

int main()
{
  for ( int x = 0; x < 10; x++ ) {
    cout<< x <
  }
  cin.get();
}

While Loop
The while loop is almost exactly the same as the do loop except that its condition is tested at the start of the loop instead of at the end... and the format is slightly different. The easiest way to see this is simply to re-write the above example with a while loop.

Example:
#include

using namespace std;
int main()
{
  int x = 0; 
 
  while ( x < 10 ) {
    cout<< x <
    x++;            
  }
  cin.get();
}

Do While Loop
The do while loop is like the while loop except that the condition is tested at the bottom of the loop.

Syntax:
do {

} while (condition);

Example:

#include

using namespace std;

int main()
{
  int x;

  x = 0;
  do {
    cout<<"Hello, world!\n";
  } while ( x != 0 );
  cin.get();
}

 
     
   
C++ Tutorial
 
  Introduction to C++
Introduction to C++
  Variables in C++
Variables in C++
  if statement in C++
if statement in C++
  Looping in C++
Looping in C++
  break & continue statements
break & continue statements
  Switch Case Statement
Switch Case Statement
  C++ Functions
C++ Functions
  Pointers in C++
Pointers in C++
  Arrays in C++
Arrays in C++
  Strings in C++
Strings in C++
  Structures in C++
Structures in C++
  C++ File I/O
C++ File I/O
  Typecasting in C++
Typecasting in C++
  C++ Classes
C++ Classes
  Recursion in C++
Recursion in C++
  Inheritance in C++
Inheritance in C++
  Initilization Lists in C++
Initilization Lists in C++
  Enumerated Types in C++
Enumerated Types in C++
  Templates in C++
Templates in C++
  C++ Preprocessors
C++ Preprocessors
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
  ASP Tutorial
ASP Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Internet Marketing 101 Ebook Internet Marketing 101
   
Download Virtualization For Dummies, Sun and AMD Special Edition  Ebook Virtualization For Dummies, Sun and AMD Special Edition
   
Download An Insiders Guide To Writing Articles Ebook An Insiders Guide To Writing Articles
   
Download Introduction to Programming (in Java) - An Interdisciplinary Approach  Ebook Introduction to Programming (in Java) - An Interdisciplinary Approach
   
Download Introduction to Interactive Programming In Java  Ebook Introduction to Interactive Programming In Java
   
 
Studiesinn.com © 2012 All Rights Reserved.
Website Designed & Developed by TechXprtz