#include <stdio.h>
#include <cs50.h>
int main(void)
int h;
h=get_int("h ");
while (h>2){
printf ("ffff");

As any integer greater than 2 entered, there is an infinite loop (ffff printed infinitely). Could anyone please explain why so.

1 Answer 1


while() will run as long as the condition inside is true. In your code, an integer >2 will make it an infinite loop because the condition will be forever true.

Alternatively, if you use if() instead of while(), it will print "ffff" once.

You must log in to answer this question.

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