First off, you need to declare the variable j somewhere. Assuming you have declared j somewhere else in the program, this program as you have written it here will actually print nothing out.
Since j is set to start at 0, and 0 is not greater than 0, the
cout<<i<<"t";
line will never actually be run. If you could provide more of your code we may be able to answer your question better. You could try setting j to start at 1 if you want it to actually print out i.
Link to Online IDE running the program
On executing the program, there is no output.
for(short i=1;i<5;i++)
This statement declares and initializes the variable i to 1, checks if it is less than 5 and then moves on to the next statement
for(j=0;j>0;j--)
This statement initializes j to 0 (Note that j has to be declared previously), and then checks if j is greater than 0. As j isn’t greater than 0, it doesn’t move on to the next statement, i.e. cout<<i<<"t";
and continues the previous loop, the loop with the variable i
.
The i
– loop runs 4 times, and since anything isn’t actually printed to the screen, you don’t get any output.
First this code won’t compile as you have not defined j. After you do that, it wont print anything as j is never greater than 0.
#include <iostream>
int main()
{
for(short i=1;i<5;i++)
for(short j=0;j>0;j--)
std::cout<<i<<"t";
return 0;
}