int main(void)

     printf("Number of blocks: "); //prompts the user for number of blocks
     int n; //height

     n = GetInt();
     while ( n > 23 || n < 0);

     for(int i = 0; i < n; i++) //i = row
      for(int sp = 0; sp - 1; sp--)  //sp = space
       printf(" "); 

     for(int c = 0; c < (i+2); c++) //c = column





https://gyazo.com/8daa119258ea28847b0be9ee2a854079infinite loop

This is my code for mario. No problems when I compile it. However, when I execute it and enter a number between the valid parameters (0-23) I get stuck on an infinite loop (as shown in the image) and I'm required to do CTRL + C to forcefully exit.

I don't want a direct answer, just point a direction to which I could follow.

Thank you in advance.

  • 1
    Firstly I would advise you to implement your code in a way respecting basic rules of style50 (implementation 4 x 4 tab, ...). Once done, you will have a much more comprehensive view of what your code is doing, from nested loops to exterior ones. Also, what your while loop supposed to do? At the moment, I think a review of your code implementation will clearly help you, and us, to find where errors come from.
    – CharlesD89
    Nov 11, 2015 at 15:11
  • Thanks, this actually helped me a lot !
    – Gabriel
    Nov 13, 2015 at 21:10

1 Answer 1


Since you wanted a pointer in the right direction instead of a specific answer, here it is. You have a broken for loop declaration. The second clause should be a test of some kind. When it isn't a test, i.e., missing something like >, <, ==, etc., it is often interpreted as always true, so it will never terminate.

BTW, the while loop is doing exactly what it should, although I might add a prompt for a number, as specified in the spec.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .