Software Information

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


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.comUse 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


MORE RESOURCES:
Unable to open RSS Feed $XMLfilename with error HTTP ERROR: 404, exiting
home | site map | contact us