Printing a variable after for loop completion

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helloworld1984
    New Member
    • Sep 2007
    • 1

    Printing a variable after for loop completion

    Hellow all, im haing a problem ending my for loop inside of a funtcion, if i want the program to cout << m; after a for loop runs how do i get it to print out a store integer?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Come again?

    kind regards,

    Jos

    Comment

    • baileylo
      New Member
      • Oct 2007
      • 2

      #3
      Yeah, you're a little vague in your problem but i think your problem could be scoping:
      Code:
       
      //Does your current looking something like this
      for(i = 0; i < 10; i++){
           int m = someArray[i];
      }
      std::cout << m;
      
      //m won't print it doesn't exist out side of for loop
      //make it look like this
      int m = 0;
      for(i = 0; i < 10; i++){
           m = someArray[i];
      }
      std::cout << m;
      Hope that answers your question.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        I've changed the thread title to be a bit more descriptive

        Comment

        Working...