Jump to content

For and while loops

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
Khaotic

Khaotic

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
These are the main loops I use when I code in any language, so I thought I make a guide on them in C++(works same way in C):

For loops: - These loops are pretty much that same as a while loop except you are able to set the incrementation and set the initial var value.
Loop example:

for(int x=1;x <= 10;x++) {

cout << x << "\n";

}

Explanation:
for(int x=1;x <= 10;x++) { - means that I am setting an integer variable with the value of 1. While x is less than or equal to 10, it will do what is defined within the braces. x++ increments x by 1 each time, the loop statement is true.

cout << x << "\n"; - That will output the value of x "\n" means go to a new line

} - That closes the loop

While loops: - This is basically does what is defined within the loop until the loop statement is no longer true

Loop Example:

int x = 1;

while(x <= 10) {

cout << x << "\n";

x++;

}


Loop Explanation:
int x = 1; - creates an integer named "x" with the value of 1

while(x <= 10) { - means while x is less than or equal to 10

cout << x << "\n"; - it will print the value of x along with the newline

x++; - increments x by 1 value

} - closes the loop

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Very nice! +rep

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Nice. :)

#4
Khaotic

Khaotic

    Learning Programmer

  • Members
  • PipPipPip
  • 62 posts
Thanks. means a lot to me
Check out my site: www.khaoticirc.net

#5
`Tim

`Tim

    Newbie

  • Members
  • Pip
  • 1 posts
nice =)

#6
BlaineSch

BlaineSch

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,448 posts
Loops are amazing and can help everybody tremendously!

#7
MathX

MathX

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,001 posts
Great, simple but helpful :)

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!


#8
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
neat tutorial +rep
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#9
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Loops are a must know if you ever decide to program so thank-you mate. It's appreciated you took the time to write this, well done.

+rep
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!