Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. help with while and for.

help with while and for.

Scheduled Pinned Locked Moved C / C++ / MFC
comhelptutoriallearning
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kh pakdaman
    wrote on last edited by
    #1

    can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com

    M L B 3 Replies Last reply
    0
    • K kh pakdaman

      can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      for(int nLoop = 0; nLoop < 10; nLoop++)
      {
      // Do something ten times
      }

      int x = 0;
      while(x < 10)
      {
      x++;
      }

      If you are a beginner, I suggest you need a few books to learn the basics of C++. Michael 'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879

      R 1 Reply Last reply
      0
      • M Michael P Butler

        for(int nLoop = 0; nLoop < 10; nLoop++)
        {
        // Do something ten times
        }

        int x = 0;
        while(x < 10)
        {
        x++;
        }

        If you are a beginner, I suggest you need a few books to learn the basics of C++. Michael 'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879

        R Offline
        R Offline
        RChin
        wrote on last edited by
        #3

        Michael P Butler wrote: If you are a beginner, I suggest you need a few books to learn the basics of C++. ..and the fact that this question was answered already, yesterday suggest, that he's not taking any of our advice! http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=613572&df=100&exp=0&fr=126#xx613572xx[^] Get a book, read the suggested website; their are a lot of free websites thats willing to teach you c++ from the ground up, including for and while loops (do a google search). **I Dream of Absolute Zero


        **

        1 Reply Last reply
        0
        • K kh pakdaman

          can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com

          L Offline
          L Offline
          Larry J Siddens
          wrote on last edited by
          #4

          Don't mind me, I'm in a teaching mood! There are three diffrent looping structures within The C Programming Language and C++ (an extension of C). There are:

          1. for
          2. while
          3. do-while

          Here is a brief description for each:

          1. for: The for loop is mainly used to step through something, like an array. It syntax is "for( staring index ; condition ; increment ) Statement" These statements can be incremented (or decremented) by a known value, like 1, 3, 5, 56, ... You don't need all the items within the paranthesis, but you do need the semi-colons. Example:
            = x;

            for( ;; )...
            Here I have an endless loop.
            for( ; x < 10; ) ...
            Here it is like the while loop.
          2. while The while loop is used to do looping until a condition is met. One example for the while would be in polling something. You continue waiting until the event occurs then drop out of the loop. You can interchange the for/while exactly like one of the post stated. The condition testing is done at the beginning of the loop.
          3. do-while This loop structure is a different animal than the rest. Unlike the for/while loops where they must first pass the condition to execute, the do-while will always execute the loop once. The condition testing is done at the end of the loop instead of the beginning.

          I hope this helps. The uses that I described are not hard and fast, but they can be used as a guide line if your new until you get more experience. Larry J. Siddens Cornerstone Communications TAME THE DOCUMENT MONSTER www.unifier.biz

          1 Reply Last reply
          0
          • K kh pakdaman

            can you make me an example with while and for, thank you,please describe everything im a beginner. thanks. bye khodadad@eminem.com

            B Offline
            B Offline
            bhangie
            wrote on last edited by
            #5

            Hi there Example, new to this myself!! :-D { //Create vector put 26 numbers into it //using for loop for(int i = 0; i < 26; ++i) { Vec.push_back(i * 2); // pushback * 2 //2,4,6,8,10...... cout << Vec.at(i) << "\n"; //Display } Not that dificult hey. Regards bhangie:-D

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups