Search
Relevant Links
Top 10 Articles
C# Binary Tree
A C# Binary Tree is a data structure not found in the .NET Framework. It is a rudimentary structure for searching through elements quickly and efficiently.
C# Binary Tree
C Programming Careers - Courses Simplified
Modern training techniques currently give trainees the facility to be instructed on an innovative style of course
C Programming Careers - Courses Simplified
Selecting The Right C Programming Course Provider
Selecting the Right C Programming Course Provider
Selecting The Right C Programming Course Provider
An Amazing Data Structure - Programming A Maze In C Plus Plus
In this article, we will take a close look at the construction of a maze of rectangular shape in C++
An Amazing Data Structure - Programming A Maze In C Plus Plus
C - The Influence Factor Of Many Popular Programming Languages
Many widely used languages that came after C such as C#, PHP, Java, LPC, JavaScript and Unix's Shell are directly or indirectly influenced by C
C - The Influence Factor Of Many Popular Programming Languages
Top 4 Reasons Why You Should Learn C-C++ Programming Today
In the programming field, your first job would be always to brush up your C-C++ programming language syntax and concepts
Top 4 Reasons Why You Should Learn C-C++ Programming Today
15 Good Programming Habits
15 Good Programming Habits
15 Good Programming Habits
Sprintf Manual
Sprintf Writes formatted data to string
Sprintf Manual
Analyzing C++ And Java - Exploring The Major Differences
Most of the developers previously have experience with an object-oriented programming language such as C++
Analyzing C++ And Java - Exploring The Major Differences
An Amazing Data Structure - Programming A Maze In C++
In this article, we will take a close look at the construction of a maze of rectangular shape in C++
An Amazing Data Structure - Programming A Maze In C++
Categories
Related Links

 

cprogramminginfo.com

Cprogramminginfo.com offers C Programming info to the Software Developer's Online Community.

If you have a question regarding programming in C, you will find your answer in our article base. If you are interested in posting Tips and Tricks or Hot programs in C then use our submit articles tab to submit your article. The C programming language is famous for its ability to produce speedy and efficient code

Loops

Loops : C++ Tutorials: 3, Program Flow (If, Else, While, For) - C Programming

 

Program Flow is what you think it is. How the program will flow. As you know the compiler will just go down the code. Program flow is what you use to make it run a certain thing a few times, do something based on a variable, etc... There are some basic comands to program flow. The first two are loops: While and For. When you want something to loop for an amount of times based on a variable, use while. If you know how many times you want something to run, use for. If and else statements are pretty self explanable. Dont be afraid, I will go over all the syntaxes and how to do everything!

The For Loophttp://www.syschat.com Use a for loop when you know how many times you want something to run. For example, we want to have an application that counts from 0 to 50 and count by fives. To do this we would need a for loop. Here is how you do it:

for(DEFINE VARIABLE; WHEN IT SHOULD STOP; How much you count every time the program runs){

Code you want to run. } Ok, so with our 0-50 program, we would do the following:

for(int x = 0; x < 51; x=x+5){

cout<<

If we wanted to count by ones, we would make the last statement x++.

While Loops
When you want to have something run multiple times, but you dont know how many, use a while loop. For example, we have a program that will ask if you want to exit and keep running until you type 'y'. Making a while loop is pretty simple:

while(case)
{
code...
}

How to write a case: Most are pretty easy, for example: x>8 However, they can get tricky: her is a list of operators to use:

Eqaul: ==
And: &&
Or: ||
Greater than or equal to: >=
Not Equal to: !=

The program that we are going to make checks if the user is writing a 'y'? So the case is going to be: While(exit!='y')

Full Code:

char exit = 'n';

while(exit=='n')

{

cout<<"Do you want to Exit (y/n)?";

cin>>exit;

}

If Statements
If you want something to run if something has a certain value, you can use an if statement. To do that, you type: if(case){code;}. If you want something to run that does not fit into that if case, you can use an else statement. To do that, you just write else{ code; } The example I am going to show you will ask someones age and say if they are old enough to drive or not:

int age;

cout<<"Age: ";

cin>>age;

if(age >=16){

cout<<"You are old enough";

}

else{

cout<<"You have "<<16-age<<" More years.";

}

cin>>age;

Go out and make a program!
I have thought up a good challenge for you that will use all the topics I have covered on this lesson: Try to make a program that will draw a box based on user input. If the user types more than 60, they have to pick a smaller number. Hint: You can put a for loop inside a for loop, and you are going to need to make the user type x, which is also going to be the y value because it is a square. If you need help, dont be afraid to ask, I can tell you how to do it or a hint if you want

Chris Silop - http://www.syschat.com, Computer Forum


Other Relevant Articles from this Category:
C++ Tutorials: 3, Program Flow (If, Else, While, For)

More Categories:
Loops  
Comments  
Functions  
Variables  
Introduction  
Operating Systems  
Libraries  
Parameters  
Preprocessor  
Pointers  
Recursions  
Examples  
File IO  
Structures  
Linked Lists  
Coding Standards  
C C Plus Plus Training