Reputation: 133
I'm new to learning how to code and I was wondering if there's a way to see values during each iteration of a loop. Here's a code I'm trying to understand. I know some of it but as it gets deeper, I get confused.
#include <iostream>
#include <string>
using std::cin; using std::endl;
using std::cout; using std::string;
int main()
{
cout << "Please enter your first name: ";
string name = "Jae";
const string greeting = "Hello, " + name + "!";
const int pad = 1;
const int rows = pad * 2 + 3;
const string::size_type cols = greeting.size() + pad * 2 + 2;
cout << endl;
for (int r = 0; r != rows; ++r) {
string::size_type c = 0;
while (c != cols) {
if (r == pad + 1 && c == pad + 1) {
cout << greeting;
c += greeting.size();
} else {
if (r == 0 || r == rows - 1 ||
c == 0 || c == cols - 1)
cout << "*";
else
cout << " ";
++c;
}
}
cout << endl;
}
}
Upvotes: 0
Views: 165
Reputation: 3061
Google is your friend.
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide
Simply you can execute your program line-by-line by pressing F10 key. And hovering mouse over variables shows their current value.
Upvotes: 0
Reputation: 189
if r is your iterator, write inside the loop this line:
cout << r;
Upvotes: 0
Reputation: 1428
You can debug your code. If you debug, you can see values during each iteration of a loop
Upvotes: 1