Skip to content

Instantly share code, notes, and snippets.

@itsjohncs
Created October 22, 2012 07:05
Show Gist options
  • Save itsjohncs/3930058 to your computer and use it in GitHub Desktop.
Save itsjohncs/3930058 to your computer and use it in GitHub Desktop.
SI Classroom Session 4 - Converting While Loops into For Loops
#include <iostream>
using namespace std;
int main() {
string name;
cout << "Please enter your first name: ";
cin >> name;
int i = 0;
while (i < name.size()) {
cout << name.at(i) << endl;
++i;
}
return 0;
}
#include <iostream>
using namespace std;
int main() {
string name;
cout << "Please enter your first name: ";
cin >> name;
for (int i = 0; i < name.size(); ++i) {
cout << name.at(i) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment