+ Reply to Thread
Results 1 to 9 of 9

Thread: For and while loops

  1. #1
    Learning Programmer Khaotic will become famous soon enough Khaotic will become famous soon enough
    Join Date
    Apr 2009
    Posts
    37

    For and while loops

    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:
    Code:
    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:
    Code:
    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. #2
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

    Re: For and while loops

    Very nice! +rep

  3. #3
    Code Slinger chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5 has a reputation beyond repute chili5's Avatar
    Join Date
    Mar 2008
    Posts
    7,023
    Blog Entries
    1

    Re: For and while loops

    Nice.
    "Whenever you remember, I'll be there/
    Remember how we reached that dream together" - Carrie Underwood

  4. #4
    Learning Programmer Khaotic will become famous soon enough Khaotic will become famous soon enough
    Join Date
    Apr 2009
    Posts
    37

    Re: For and while loops

    Thanks. means a lot to me
    Check out my site: www.khaoticirc.net

  5. #5
    Newbie `Tim is an unknown quantity at this point
    Join Date
    Jul 2009
    Posts
    1

    Re: For and while loops

    nice =)

  6. #6
    Code Warrior BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch is a glorious beacon of light BlaineSch's Avatar
    Join Date
    Apr 2009
    Location
    Trapped in my own little world.
    Age
    19
    Posts
    2,223
    Blog Entries
    8

    Re: For and while loops

    Loops are amazing and can help everybody tremendously!

  7. #7
    Guru MathX has a spectacular aura about MathX has a spectacular aura about MathX's Avatar
    Join Date
    Oct 2008
    Location
    Kosovo
    Age
    19
    Posts
    4,006

    Re: For and while loops

    Great, simple but helpful

  8. #8
    Code Warrior
    /////////|||||\\\\\\\\\
    amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama's Avatar
    Join Date
    Aug 2007
    Location
    Pyramids st, Giza, Egypt
    Age
    21
    Posts
    8,182
    Blog Entries
    12

    Re: For and while loops

    neat tutorial +rep

  9. #9
    Code Warrior Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W is a name known to all Brandon W's Avatar
    Join Date
    Sep 2008
    Location
    Australia
    Age
    16
    Posts
    4,824
    Blog Entries
    10

    Re: For and while loops

    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!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts