if statement inside for loop not working

The output of the below code should be the numbers between 21 and 29. But the output is numbers between 15 and 30. Where is the mistake? Why is if statement inside for loop not working?

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;
int main() 
{
int i,num=15;	
for(i=num; i<=num+15; i++)
{
if(20<i<30)
cout<<i<<endl;
}
return 0;
Last edited on
if(20<i<30)This is not the proper synthax. Should be if (i > 20 && i < 30)
Topic archived. No new replies allowed.