mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-08-20 05:21:26 +02:00
Reworded incrementing operators in C.
This commit is contained in:
@@ -261,8 +261,7 @@ int main() {
|
|||||||
// While loops exist
|
// While loops exist
|
||||||
int ii = 0;
|
int ii = 0;
|
||||||
while (ii < 10) { //ANY value not zero is true.
|
while (ii < 10) { //ANY value not zero is true.
|
||||||
printf("%d, ", ii++); // ii++ increments ii in-place
|
printf("%d, ", ii++); // ii++ increments ii AFTER using it's current value.
|
||||||
// after yielding its value ("postincrement").
|
|
||||||
} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
} // => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@@ -270,8 +269,7 @@ int main() {
|
|||||||
int kk = 0;
|
int kk = 0;
|
||||||
do {
|
do {
|
||||||
printf("%d, ", kk);
|
printf("%d, ", kk);
|
||||||
} while (++kk < 10); // ++kk increments kk in-place, and yields
|
} while (++kk < 10); // ++kk increments kk BEFORE using it's current value.
|
||||||
// the already incremented value ("preincrement")
|
|
||||||
// => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
// => prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
Reference in New Issue
Block a user