C language, while in parentheses should not be executed twice

Updated on technology 2024-06-04
25 answers
  1. Anonymous users2024-02-11

    Solution: Execute it once.

    Knowledge: While is a basic cyclic pattern of computers. When the condition is met, it enters the loop, and after entering the loop, when the condition is not met, it jumps out of the loop. The general expression of a while statement is: while (expression).

    a++ and ++a are both self-incrementing operators, with the difference that the value of variable a is self-incremented at different times. A++ is to take the value first, and then auto-increment. ++a is the autoincrement first, and then the value.

    The program starts by first executing the while expression (--b,c--,a--).

    The expression is executed from left to right, and if it is true, it continues to be executed. --b (subtract first and then take the value), that is, b=1 is true; c--(take the value first and then subtract itself), that is, c=2 is true; a--(take the value first and then subtract it), that is, a=1 is true; So if the expression is true, it enters the loop body, which is the execution output the values of the three variables.

    After the first loop, the values of each variable are, b=1, c=1, and a=0.

    Execute the loop body, output a=0, b=1, c=1.

    In the second loop, execute the expression (--b,c--,a--)b (first subtract and then take the value), that is, b=0, which is false, does not meet the condition, and jumps out of the loop.

  2. Anonymous users2024-02-10

    In C, the judgment in parentheses in while is executed twice, but the loop is executed only once. So you should choose answer D.

  3. Anonymous users2024-02-09

    Your while is a comma expression, evaluated from left to right, with the rightmost value as the value of the whole expression, when making a---judgment, because it is a post-subtraction, so a is still 1 at this time (in c non-0 is true), so if the condition is met, the following printf will be executed, note that at this time, a b c is reduced by 1, so the output result is 0, 1, 1, in the second cycle, also because a--, a at this time is 0, the whole expression is false, So the printf is no longer executed, and the answer is d.

    Of course, the while judgment is indeed performed twice, and the second judgment is false before the printf is executed, if you add another line at the end.

    printf("%d,%d,%d",a,b,c);

    You can see that after the second judgment, the abc is -1, 0, 0 respectively

  4. Anonymous users2024-02-08

    <> outer layer while(d < f), the d and f values do not change and are always satisfied.

    The inner layer while (c == runs once, ab c is the content of user input (e.g. a='a',b='b',c='!The while condition is satisfied, but c replicates c= again in the inner while'a', the inner layer while is not satisfied, and the memory while exits.

  5. Anonymous users2024-02-07

    The mean: The while() statement means:

    When the condition in () is not met, the loop is broken.

  6. Anonymous users2024-02-06

    You take a screenshot of the input and output screens.

  7. Anonymous users2024-02-05

    No, only if the while loop condition is not true, the latter loops one more time than the former.

    Everything else is exactly the same.

    do while is the loop body that is executed at least once.

    The loop body of while can be executed 0 times.

  8. Anonymous users2024-02-04

    do...A while loop executes a loop body statement more than a while loop.

    Here's why: do....While executes the loop statement first, and then determines the loop condition.

    While is just the opposite, that is, the loop condition is judged first, and then the loop statement is executed.

    For example: int i=0;

    int a=0;

    dowhile(i>0);

    After execution, a=1

    int i=0;

    int a=0;

    while(i>0)

    After the execution is complete, a=0

    As you can see from the two examples above, do....While loops do execute loop body statements once more than while loops.

  9. Anonymous users2024-02-03

    The difference is:

    The while statement first determines the conditions in parentheses after the while Executes the program in {} according to the truth or falsehood of the conditions.

    do while always executes the {} statement first, and then determines the condition in parentheses after while, if it is true, it executes the {} statement first.

    The understanding of one more cycle is not entirely correct.

    For example: unsigned char x = 0;

    while(x<1)

    //////////////////////unsigned char x = 0;

    dowhile(x<1);

    Both of these statements are perfectly correct, both of which are judged to be x<1, but they are only executed once.

  10. Anonymous users2024-02-02

    do while is a loop that executes while at least once, and can be executed 0 times or more.

    Moreover, while is generally used, because while can basically include do while in execution

  11. Anonymous users2024-02-01

    That's right, because the former is to judge first and then execute, and the latter is to execute first and then judge, and there is one more run out of thin air.

  12. Anonymous users2024-01-31

    The number of loops is not the key, the key is that the while must meet the conditions before it is executed. do while is the ** that is being executed, and then the condition is judged, whether it is still to be executed. This is the essential difference between the two.

  13. Anonymous users2024-01-30

    While will only be executed if the condition is true. do while will be executed at least once regardless of whether the condition is true or not.

  14. Anonymous users2024-01-29

    You see, that's the essential difference. Don't listen to those sand sculptures

  15. Anonymous users2024-01-28

    In the C world, everything except 0 is false.

    The while(1) statement is correct to determine that the condition is an endless loop, but it is not necessarily an endless loop, and it may run out of the while loop at a certain point.

    For example, while(1) runs to break, or return, then the current while statement will be terminated and the loop will be terminated. The interrupt mentioned above only jumps out of the while statement for a while, executes other statements, and returns to while(1) to continue the loop after the execution.

  16. Anonymous users2024-01-27

    The usage of the while loop is:

    while (judging condition).

    If the judgment condition is true, the internal loop is implemented**;

    If the judgment condition is false, the loop is jumped out and the follow-up ** is executed.

    When the judgment condition is true, the value is 1; When the judgment condition is false, the value is 0, so while 1 is an infinite loop.

  17. Anonymous users2024-01-26

    This is because while() is executed in a loop when the expression is judged to be true.

    In C, there are no bool types, only macros true(1) and false(0). Any number other than 0 is true in C

    In C++, there are dedicated bool types true and false

  18. Anonymous users2024-01-25

    If 1 is written in a place where it needs to be true or false, then it must be that you can't decide whether it's a number or a true or a fake, and you can see where it's placed. For example, if (1) while (1) for (; 1;) will be interpreted as true or false, if a = a + 1; It will be used as a number.

    There are no true and false keywords in the C language, true or false is represented by integers or pointers, 0 is false, and everything else is true

  19. Anonymous users2024-01-24

    Because as long as the parentheses in the while statement are not 0, the loop will be looped, and the negative or positive numbers will be looped. So while(1) will keep looping, and if you want to break out of the loop, you can use the break statement.

  20. Anonymous users2024-01-23

    The number in c: 0 is false, and all non-0 values are "true".

    While is only serious and false, 1 is a number and not 0, that is true.

  21. Anonymous users2024-01-22

    You can choose to use the header file to directly use true for true, false for false, and c for logical operations, where 0 is false and non-0 is true.

  22. Anonymous users2024-01-21

    If you want to indicate characters, you should put them in quotation marks.

  23. Anonymous users2024-01-20

    The while loop is an expression after the while parentheses.

    To make a judgment of truth or falsehood, for example, there is such a provision in the language A and C you use, if a=0; Then alas

    If a is not 0, then he is true, therefore, the above loop, as long as a is not equal to 0, then the cycle goes on all the time.

    When I first started learning, I always thought that it was only true when it was equal to 1, and he couldn't loop if it was equal to 2, but that was wrong, the compiler.

    The criterion for judging the true or false conditions is that he is not equal to 0, not equal to 1, the landlord remembered

    There is also,If the landlord's will is to let a=0 exit the loop,Then you can follow the method you wrote,If the will of the landlord is to let a=0 when the cycle is made,Then Pei Huainian has 2 ways to write。

    while(!a)

    Non-operation on A.

    And there is. while(0==a)

    It is recommended to write 0==

    The form of a, in fact, 0==a, is essentially the same as a==0, but if you say 0==a and write it as 0=a, then the compiler will report an error, and the compiler will .

    If a==0 is written as a=0, the compiler will not report an error, which can reduce the risk.

    Good luck!

  24. Anonymous users2024-01-19

    Meaning if a

    If true, execute the loop body in while!

    a) Cycle conditions for town and bend! But an endless loop! Because there is no way to determine whether the value of a is true or false!

    Write an example!

    inta=0;

    while(a<5)

    a++;printf("%d",a);

    When a=0, a<5 is judged to be true! Perform the loop body!

    This cycle is a total of 5 times! That is, you can run A++ 5 times and see what the effect is every time! It can deepen your understanding of the cycle!

    Hope it helps!

  25. Anonymous users2024-01-18

    The syntax of while is.

    while (expression).

    When the expression is not 0, the sentence buried in the sentence body will be executed.

    It doesn't stop until the expression is 0.

    The while statement is generally used in an endless loop.

    So the regular usage is while(1).

Related questions
9 answers2024-06-04

There are generally 2 ways to use while.

1. While (judgment condition). >>>More

9 answers2024-06-04

Scope. You static char *chh;

static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More

5 answers2024-06-04

In fact, it is much easier to read by adding parentheses to the first part of your formula! They are the same! >>>More

11 answers2024-06-04

Valid variable names for the C language:

First, it can only contain numbers, letters, and underscores. >>>More

5 answers2024-06-04

First, 3 linklist types list, p, and r. are declaredYou can think of list as a table, but at the beginning it is an empty table, list is assigned to r, start a for loop, specify the next node of r as p (head node), and then assign p to r, the next node of the head node is list, list is assigned to p, enter a from the keyboard, if a > 0, then the data part of the second node is the value of a, and the cycle continues, and the condition for the end is to enter the value a>=0, when p is sure to reach the last node after the while loop ends, p is assigned to r, r is the end node, and then output with do while, output the data of each node, and the end condition is p to the end node. To put it bluntly, first create an empty table k-1 node, then input the keyboard to assign the value of the data part of each node to "0", and finally output the input value.