Looping is when you want to do something many times.
For example you want to output a 5 times.
for(int iteration = 1; i < 5 ; i++){
cout << "a";
}
*note :
i++ is equal to i = i + 1
The first is initial statement. If you don't need if just skip it, but always put semicolon (;).
int iteration = 1;
for(; i < 5 ; i++){
cout << "a";
}
The second is the condition to break from the loop.
The last is the statement that happen after each iteration.
Exercise :
Life, the Universe, and Everything
Adding Reversed Numbers
*Important
For SPOJ, and other judge online, always output new line in the end.
For example you want to output a 5 times.
for(int iteration = 1; i < 5 ; i++){
cout << "a";
}
*note :
i++ is equal to i = i + 1
The first is initial statement. If you don't need if just skip it, but always put semicolon (;).
int iteration = 1;
for(; i < 5 ; i++){
cout << "a";
}
The second is the condition to break from the loop.
The last is the statement that happen after each iteration.
Exercise :
Life, the Universe, and Everything
Adding Reversed Numbers
*Important
For SPOJ, and other judge online, always output new line in the end.
Komentar
Posting Komentar