I am trying to understand the output of this program. If I try to "translate" the code, I believe it should go like this:
- while "j" is smaller than 3 - print "Ha" (this loop goes 3 times, so it gives 3 "Ha")
- do/while -> j is equal to j - 2 hence print "Hi" while ++j - In the end the program prints out "Hi" 4 times.
How does the program prints it 4 times, how does the condition works here?
#include <stdio.h>
int main() {
int j = 0;
while(j++ < 3){
printf( "Ha ");
}
do{
j -= 2;
printf( "Hi ");
}
while(++j);
for(j = 1; j <= 3; j++){
printf( "Ho ");
}
printf("\n");
return 0;
}
The output is:
Ha Ha Ha Hi Hi Hi Hi Ho Ho Ho