Author Topic: Question about Loops  (Read 2496 times)

Offline Apbullington18

  • Single posting newcomer
  • *
  • Posts: 2
Question about Loops
« on: October 23, 2018, 05:47:38 pm »
#include <stdio.h>
main()
{
int x = 0;
while (x < 5)
{
    printf(" ",x,"\n");
    x++;
}
return 0;
}

I can't get this program to run in CodeBlocks.  It's just a simple while loop, but nothing comes out when run.  I'm new to coding so forgive me if i'm naive. 

Offline raynebc

  • Almost regular
  • **
  • Posts: 217
Re: Question about Loops
« Reply #1 on: October 23, 2018, 07:10:08 pm »
That printf statement isn't doing what you think it is, it's just printing space characters.  You'll probably want to do printf(" %d\n", x); instead.  If you enabled all the optional warnings in your compiler, you would likely get a warning that you passed too many arguments (ie, x and "\n" being ignored because the format string didn't call for the use of any additional arguments).

Offline Apbullington18

  • Single posting newcomer
  • *
  • Posts: 2
Re: Question about Loops
« Reply #2 on: October 23, 2018, 07:51:48 pm »
That fixed it!  Thanks!