Hey everyone, I'm a beginner and I'm really struggling with understanding why my C for loop isn't working as I intended. I want it to print the following:
aa
a
Instead, I'm seeing this:
aa
aa
aa
Here's the for loop I wrote:
for (int j = h; j > 0; j--)
I think there might be an issue with the loop condition j > 0, but I can't figure out what's wrong. Can anyone help me understand why it's not working as expected? Any advice would be greatly appreciated!
3 Answers
Actually, with the code you’ve shared, looping backwards over `h` might not even be necessary. Also, it looks like in your `main()` function, you’re passing a constant value (`h-1`) to the `print_row()` function, which would affect your output. Definitely worth checking!
Could you share more of your code? The loop condition itself looks fine, but I wonder what’s going on inside the loop. Are you sure you’re using `j` where you should instead of `h`? That might be the problem!
You might want to try using j = h - i instead. That could fix the issue you're running into.

Sure thing, here’s what I’m working with: https://imgur.com/a/ZXHgp2D