Python has an interesting for
statement which lets you specify an else
clause.
In a construct like this one:
for i in foo:
if
I would accomplish this with a simple helper variable:
#include
#include
int main()
{
bool b;
printf("Numbers which are multiples of 7:\n");
for (int i=8; b=(i<12); i++)
{
if (i%7==0)
{
printf("%d", i);
break;
}
}
if (!b)
{
printf("no numbers found\n");
}
return 0;
}
This way, you need to implement the condition (in the above examplei<12
) only at one place.