how would I write a for loop to print all the multiples of 5 from 25 up to and including the value of the integer variable limit.
and how do i make it exit the loop if the value is greater than 100?
#include <iostream>
int main()
{
int limit = 150;
for( //how would I write a for loop
int i = 25; //from 25
i <= limit; //up to and including the value of the integer variable limit
i += 5 //all the multiples of 5
)
{
//to print
std::cout << i << std::endl;
if (i > 100) //if the value is greater than 100
{
//make it exit the loop
break;
}
}
return 0;
}
EDIT: You would normally write all the for-loop stuff before that for loop's opening brace '{' on the same line, but I broke it up so that I could append a comment to each part.
The limit is unspecified in the question. I assumed that the limit may be variable, and it could be greater than, less than, or equal to 100. I think this question is meant to get the OP to create a for loop and to invoke a statement to alter control flow within a loop based on some condition.