#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    33
    Rep Power
    12

    Is there a way to change a variable inside a loop?


    I have 2 tasks to perform on 9 different objects.


    Example


    Code:
    
    ping += default_host1;
    std::cout << " Pinging: " << default_host1 << "\n";
    run_program(ping, GetStdHandle(STD_INPUT_HANDLE), diagnostics, GetStdHandle(STD_ERROR_HANDLE));
    
    traceroute += default_host1;
    std::cout << " Traceroute: " << default_host1 << "\n";
    run_program(traceroute, GetStdHandle(STD_INPUT_HANDLE), diagnostics, GetStdHandle(STD_ERROR_HANDLE));
    Each iteration I need to change the string added to ping.

    default_host2, default_host3, so forth and so on.

    Is this possible?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    No es importante
    Posts
    2,065
    Rep Power
    14
    Are you just wanting to append new data to ping?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    33
    Rep Power
    12
    Yes I think so.
    Not sure if it would be considered new data since I don't want to add to the exisiting data appended to ping just replace it.


    Pass 1:
    ping += default_host1

    Pass 2:
    ping += default_host2

    Pass 3:
    ping += default_host3

    etc.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    No es importante
    Posts
    2,065
    Rep Power
    14
    If you do not want to append the data but replace just set ping = default_host(1)
    or default_host(2) or default_host(3) or whatever the value is.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    33
    Rep Power
    12
    Is there a way to do this with a loop?

    Changing ping's value with the different hosts each time it loops?
    Last edited by Ornafiel; July 10th, 2003 at 08:48 AM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    No es importante
    Posts
    2,065
    Rep Power
    14
    for (i=0; i < numberOfHosts; i++)
    {
    ... get host value
    ... assign ping value
    ... do something
    }
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    33
    Rep Power
    12
    Thank you.

IMN logo majestic logo threadwatch logo seochat tools logo