none
How to separate two For loop columns in C++

    Question

  • Hi. I need to separate two For loops in C++

    I have:

    #include <iostream>

    #include <iomanip>

    using namespace std;

    int main()

    {

    int i,v;

    for(i=0;i<=10;i++)

    {

    }

    for (v=10;v<=20;v++)

    {

    }

    return 0

    }

    --------------------------------------------------------------------------------------

    I need that in result:

    0    10

    1    11

    2    12

    3    13

    4    14

    5    15

    6    16

    7    17

    8    18

    9    19

    10    20

    Thanks.


    ______________________________________________________________ Sincerely! Khalid Garayev


    Sunday, April 2, 2017 6:24 PM

Answers

  • There is no need for two variables since v can be expressed as i+10.  But in keeping with your example, you could use

         for (i=0, v=10; i <= 10; i++, v++)
              {
               cout << i << "   " << v '\n';
              }


    You will have much better luck discussing C and C++ questions in the forums dedicated to those topics.
    Monday, April 3, 2017 1:33 AM

All replies

  • There is no need for two variables since v can be expressed as i+10.  But in keeping with your example, you could use

         for (i=0, v=10; i <= 10; i++, v++)
              {
               cout << i << "   " << v '\n';
              }


    You will have much better luck discussing C and C++ questions in the forums dedicated to those topics.
    Monday, April 3, 2017 1:33 AM
  • Thank you. it's good. It's only for condition where value =10. Again thanks.

    ______________________________________________________________ Sincerely! Khalid Garayev


    Monday, April 3, 2017 6:53 AM