#include /**************************************************************** * Write a for loop that prints the integers from 0 to 9, * and then write a second for loop that prints the integers * from -2 to 7. ****************************************************************/ // Function declarations int main(); // Function definitions int main() { // What happens if you run this without // filling in the for-loop statement? for ( ; ; ) { std::cout << 0 << " "; } std::cout << std::endl; for ( ; ; ) { std::cout << 1 << " "; } std::cout << std::endl; return 0; } // Hint: Your loop variable 'int k' should be // initialized with the first value to be printed. // The condition should remain true until 'k' // becomes greater than the upper limit. // The increment should simply add one to 'k'. /* All three of these solutions work. Try to determine why all three produce the same output. int main() { for ( int k{ 0 }; k <= 9; ++k ) { std::cout << k << " "; } std::cout << std::endl; for ( int k{ -2 }; k <= 7; ++k ) { std::cout << k << " "; } std::cout << std::endl; return 0; } int main() { for ( int k{ 0 }; k < 10; ++k ) { std::cout << k << " "; } std::cout << std::endl; for ( int k{ -2 }; k < 8; ++k ) { std::cout << k << " "; } std::cout << std::endl; return 0; } int main() { for ( int k{ 0 }; k != 10; ++k ) { std::cout << k << " "; } std::cout << std::endl; for ( int k{ -2 }; k != 8; ++k ) { std::cout << k << " "; } std::cout << std::endl; return 0; } */