Home > Software engineering >  How does this function work the other way? [closed]
How does this function work the other way? [closed]

Time:09-17

Obviously, if we write 'x < 10' then, x is smaller than 10. However, it's not the case here

int n;
do
{
    n = get_int("width");
}
while (n < 10);


for (int i = 0; i < n; i  )
{
    printf("?");
}
printf("\n");

If we wanted to print '?' the same number as the user input, it will only print when numbers are larger than 10 while it shouldn't. Because n is not smaller than 10... the loop shouldn't run.

So how is that possible?

CodePudding user response:

...it will only print when numbers are larger than 10 while it shouldn't.

Why shouldn't it? The first loop gets an int from the user, if the user inputs a value that is smaller than 10, it will continue asking the user for a new input, if the user inputs a value larger than or equal to 10 the while loop will end and n will have the input value, then the for loop is executed, if n is, for example, 15, it will run 15 times and consequently print ? 15 times.

CodePudding user response:

The While continue loop until n Is less than 10. Only when n Is 10 or more your program exit from while loop and print.

  • Related