Which of the following is an infinite loop

Updated on science 2024-05-14
13 answers
  1. Anonymous users2024-02-10

    The first one is an infinite loop, and the second one is a finite loop.

    Why? The analysis is as follows:

    do{}while() uses the statement in while parentheses as a judgment to determine whether to continue executing the statement in {}.

    The k>0 in the first parenthesis is an infinite loop because the assignment is 32764 and k++ is executed, so that k>32764>0 is an infinite loop.

    The left s++%2 in the second parenthesis is the first %2 value is 0, the right s%2 is 32764%2 The result is 16382, the remainder is 0, so the value is also 0, and the left 0 and the right 0 do or operate, the result is 0, so it jumps out of the loop.

  2. Anonymous users2024-02-09

    The second is an infinite loop.

    The k in the first program will overflow at some point, and when it overflows, the value of k will become negative, and k>0 will not hold, so it is not an infinite loop.

    In the second program, even if the s overflow, it will still be satisfied"One of s and s+1 is not divisible by 2"conditions, so it will go on forever.

    Your book is ready to throw away! You can read the book and judge it based on everyone's speeches! The first one is definitely not an infinite loop.

  3. Anonymous users2024-02-08

    The first k all the way ++ will overflow the shaping range, and k becomes negative, so it's not an infinite loop.

    The condition for the second while is that k is even or odd, because k is either even or odd regardless of overflow, so it is an infinite loop.

  4. Anonymous users2024-02-07

    The first. Because k is assigned to 32764

    The judgment is k>0 executed as k++ k++ so k is always greater than 0, so it is an infinite loop!

  5. Anonymous users2024-02-06

    The second one, because the second one will have a case where %2 is not 0 no matter what, so the cycle continues.

    And the first one will make k negative because it crosses the bounds, then "0" is not valid and exits.

  6. Anonymous users2024-02-05

    Well, the reason why the second one is not an infinite loop is because the post++ will always self-increment after the statement is executed, so it just determines when it is divisible by 2.

  7. Anonymous users2024-02-04

    Both are infinite loops.

  8. Anonymous users2024-02-03

    The syntax for for is:

    for(loop initialization statement (can be omitted); Judgment loop termination condition statement (can be omitted); The statement that runs at the end of each round of the loop (can be omitted).

    Syntax for while:

    while (judgment loop termination condition statement (cannot be omitted)).

    Let's take a look at the topic:

    a. for(; x=0)

    This is the for statement. The "loop initialization statement" and are omitted"Judgment loop termination conditional statement", and the execution statement at the end of each loop is: x=0

    Because omitted"Judgment loop termination conditional statement", hence an endless loop.

    b. while(x=1)

    This is the while statement, and the "statement that determines the end of the loop" is: x=1. A statement is an assignment statement, not a logical condition (x==1) statement.

    The value of this assignment statement, which is the value of variable x, is always equal to 1. Values that are not 0 are the same in C"Really", so the cycle will continue to be executed.

    x=1;x>=++y;x++)

    This is the for statement.

    Loop initialization statement" is: y=2,x=1

    Judgment loop termination conditional statement"is: x>=++y

    At the end of each loop, the execution statement is: x++

    Let's see"Judgment loop termination conditional statement"is: x>=++y

    On the first cycle, x=1, +y = y+1 = 3. Therefore, the logical judgment statement > value of x=++y is "false".

    This cycle will not be executed once. It's not an endless loop.

    x=1;++y);

    This is the for statement.

    Loop initialization statement" is: y=0

    Judgment loop termination conditional statement"is: x=1

    At the end of each loop, the execution statement "is: +y."

    We can see that the value of the variable x does not change no matter how many times it is looped, and x is always equal to 1.

    Only the value of y is incremented by one every time it is cycled.

    Therefore"Judgment loop termination conditional statement"is: x=1 is constant. It's an endless loop.

  9. Anonymous users2024-02-02

    This contains a simple judgment that the condition of c is not satisfied, so it is c

  10. Anonymous users2024-02-01

    C should be chosen, and the condition of x>=++y is not met at the beginning, so the for loop statement jumps out at the beginning.

  11. Anonymous users2024-01-31

    a)for(k=-1;-10 errors, k=-1 should be lowercase k not an infinite loop, k <-10 after -10, exit.

    b)for(i=1,j=10;i-j;i++,j--) is an infinite loop, i-j can only exit if i-j=0, when i=5, j=6, and the next cycle i=6, j=5, i-j is never 0

    c)for(k=1;k=10;k++)

    is an infinite loop, k=10 is the assignment expression, and it is always true.

    d)for(k=1;k>0;k++)

    is an infinite loop, and k increments from 1, so k>0 is always true.

  12. Anonymous users2024-01-30

    The answer is b, where 0<=i<=5 of a, when i is 0 to 5, the value of i<=5 is 1, and when i is more than 5, the value of i<=5 is 0, that is to say, 0<=0 or 0<=1 is always true, and the loop goes on wirelessly;

    where c, when i increases to 2, i%2 is false, that is, i is always 2, the judgment is always false, i does not perform the self-increment operation, and the loop goes on wirelessly;

    Look at b again, when i is 1, the remainder of 2 is 1, 1=1 is true, the cycle is once, when i increases to 2, the remainder of 2 to 2 is 0, 1! =0, the cycle stops.

    So b is a non-infinite loop.

  13. Anonymous users2024-01-29

    The answer is b

    To answer this question, we should first clarify a few knowledge points:

    The execution process of the statement.

    2.How the value of the expression is generated.

    Let's talk about the execution process of the for statement first, so as to form it like for(a; b;c) for example:

    Before starting the loop, a is executed;

    Before each loop, check whether the value of the b expression is 0, and exit if it is 0;

    At the end of each loop, execute c

    Talking about how the value of the expression is generated, there are three kinds of expressions, self-increment, modulo, and comparison. For an auto-incrementing expression like i++, the value is the value before i self-incrementing, while for a self-increasing expression like ++i, the value is the value of i after self-incrementing. The expression value of the modulo is its result; Comparison expressions such as 0<=i<=5 can be equivalent to 0<=(i<=5) according to the order of most C compilers (from right to left), and the value of each comparison expression is 0 or non-0 (0 or 1 for the general C compiler), then the evaluation process becomes:

    0<=i<=5 => 0<=(0 or 1) => 1 Let's go back to the options, as mentioned above, the value of the conditional statement in a is always 1, so it is not true to b, i self-increments and then takes the modulo value of 2 to 0, that is, to exit the loop.

    c, after the same self-increase, the self-increase condition is not satisfied during the recycle, so it is impossible to exit the cycle.

Related questions
7 answers2024-05-14

If the phone restarts automatically and the machine cannot be used normally, it may be a problem with the system or hardware of the phone, and it is recommended that you send the device to a Samsung service center for inspection. >>>More

5 answers2024-05-14

Infinite loop decimals.

A digit after the decimal point begins to repeat the decimal system of the previous digit or sections. >>>More

23 answers2024-05-14

Yes, you need to make it into a fraction first.

Infinite cyclic decimal numbers belong to rational numbers, which can be expressed in the form of fractions, and fractions can be directly added and subtracted, so infinite cyclic decimals can be directly added and subtracted. >>>More

16 answers2024-05-14

This is not a proposition, or a false proposition. It should be said that the numbers in all real numbers, except for rational numbers, are irrational numbers and true propositions. >>>More

17 answers2024-05-14

Since the number of decimal places is infinite, it is obviously impossible to write ...... tenths, hundredths, thousandthsof the number. In fact, the difficulty of cyclic decimal fractions lies in the infinite number of decimal places. So I'll start here and find a way to "cut off" the "big tail" of the infinitely looping decimals. >>>More