What s wrong with the for loop here?

Updated on technology 2024-05-13
15 answers
  1. Anonymous users2024-02-10

    for loop: add continue where you want to skip the remaining version of the loop;

  2. Anonymous users2024-02-09

    Where you want to skip the remaining statements in this loop, add.

    continue;

    In this way, the statement after continue in this loop will be skipped and go directly to the next loop.

  3. Anonymous users2024-02-08

    The specific statement is as follows: copy:bai

    for i = 1 to 6

    lable1:

    if i = 3 then

    i = i + 1

    goto lable1

    end if

    msgbox i

    nextfor loop:

    The for loop is open to the DU realm. Its general form is: for(; Condition Table: Zhi Da Formula"; Statement; Initialization is always a DAO assignment statement, which is used to assign initial values to cyclic control variables; A conditional expression is a relational expression that determines when to exit the loop; Increment defines how the loop control variable changes after each cycle.

    Used between these three parts";"Apart. For example: for(i=1; i<10, the cycle ends.

    The for statement, which is more flexible than both while and do-while, is a more powerful and commonly used loop statement, and its general syntax format is:

    for(Expression1; Expression 2; Expression 3).

    The representation can be omitted, but the semicolon cannot be omitted.

  4. Anonymous users2024-02-07

    for the first one in parentheses of the loop"; It is a single-time expression that does not participate in the loop, which can be used as an initial assignment statement for a variable, and is used to assign an initial value to the loop control variable. It can also be used to evaluate an expression that is not related to the for loop but precedes the loop section.

    The conditional expression between the signs is a relational expression that is the formal beginning of the loop, and when the conditional expression is true, the intermediate loop body is executed.

    The executed intermediate loop can be a single statement or multiple statements, and when there is only one statement in the land intermediate loop, the curly brace {} can be omitted, and the end loop can be executed after the intermediate loop is executed.

    After executing the end of the loop, the early high source will judge the condition again, if the condition is still true, it will continue to repeat the above cycle, and when the condition is not true, it will jump out of the current for loop.

    Note: 1. The variables in the for loop can be one or more.

    2. The statement in the for loop can be the body of the sentence, and the parentheses are added outside the body"{} encloses the statement that participates in the loop.

    3., for loop"A single expression"、"Conditional reminding expressions"with"Circular body statements"are all options, i.e. they can be defaulted to "only"; ".

  5. Anonymous users2024-02-06

    The keywords commonly used in the for loop are as follows:break: used to terminate the execution of a statement block. It is used in the loop statement body to forcibly exit the loop.

    Here are some examples:public class test

    Used to terminate the execution of a block of statements. It is used in the loop statement body to forcibly exit the loop.

    public static void breaktest()+" ");}

    public static void main(string args)

    Running Result:

  6. Anonymous users2024-02-05

    For can be used to break out of the termination loop.

  7. Anonymous users2024-02-04

    Enter continue to skip the current loop. break, to break out of the current loop.

    The for loop is open. Its general form is: for(; Conditional Expressions; Statement; Initialization is always an assignment statement that is used to assign an initial value to a loop control variable.

    The statement in the for loop can be a statement body, but it needs to be used""{} encloses the statement that participates in the loop.

    , for loop"Parameter initialization expressions"、"Conditional Expressions; "with"Update the loop variable expression"are all optional, i.e. can be default, but";"It cannot be default. Initialization is omitted, indicating that no initial value is assigned to the loop control variable. If the conditional expression is omitted, it becomes an endless loop if nothing else is done.

    If the increment is omitted, the loop control variable is not operated, and the statement modifying the loop control variable can be added to the statement body. The three expressions of the for loop are all comma expressions, which means that each expression can be composed of several expressions, with the middle used", "spaced."

    For loops can be nested in multiple layers.

  8. Anonymous users2024-02-03

    These are.

    The structure of the loop program commonly used in the programming language, the operations performed are similar, but the details must be paid attention to, and it is enough to write your own program to master for and while, but to read other people's programs, you must fully grasp it.

    The following is an example of the C language.

    Cyclic structure 1for(i = 1; i < 10;i++)

    The first time you enter the loop, you first assign the initial value i = 1 to i (this operation only happens for the first time, and you will not perform such an operation in the future), judge whether the condition meets i < 10, if it is true, continue to execute the loop body, and execute the i++ operation, otherwise, jump out of the loop body and execute the statement below the loop body in order. As you can see, if the condition is not met when the first one enters the loop, the loop is skipped.

    Circular structure 2while ("Condition").

    The loop first determines the condition, executes the loop body if it is true, and executes the loop body if it is false, and executes the statements below the loop sequentially. The similarity with the for loop is that the conditions are first judged to be true or false.

    3. Circulating structure 3

    do while

    The biggest difference between this type of loop and the above two types is that the statement of the loop is executed first, and then the truth or falsity of the conditions is judged. In addition, it should be noted that the conditional change statement must be written into the loop body of the latter two cyclic structures, similar to i++ in the for structure, otherwise, it will become an "endless loop".

    Comparing the above three cyclic structures, it can also be found that the control variable of for is an integer, which is very convenient for operations such as arrays, while the control variables of the latter two types are not so strict, and have a more flexible range of use than the for loop body.

  9. Anonymous users2024-02-02

    As long as the specified condition is true, the statement block is executed.

    for (initialization; test; increment)

    statements

    Parameter initialization

    Required. An expression. The expression is executed only once before the loop is executed.

    test is required. A boolean expression. If test is true, the statement is executed. If test is false, the loop ends.

    increment

    Required. An expression. The incrementing expression is executed at the end of each loop.

    statements

    Optional. test is true, one or more statements to be executed. Can be compound statements.

    Describes the number of times the loop is to be executed, usually using a for loop.

    Example: The following example illustrates a for loop.

  10. Anonymous users2024-02-01

    The format of the for statement is.

    for(Expression1; Expression 2; Expression 3).

    Your program is:

    for( j=0; j<5; j++)

    The for statement process is:

    1. Calculate the value of expression 1;

    2. Judge expression 2, when its condition is true, execute the loop statement, and then execute step 3 (you are j<5 so the execution condition should be j= 0,1,2,3,4. If you want to execute j=5, you can use j<6 or j<=5);

    When the condition of expression 2 is not true, end the loop and execute step 5.

    3. Computational expression 3; (Note that step 2 requires the execution of the loop statement before step 3).

    4. Go back and continue to step 2;

    5. When the loop ends, execute the subsequent statements of the for statement.

    If your loop doesn't jump out, it should be that somewhere in your loop statement the value of j is always below 5, so the loop doesn't stop, but continues to execute.

  11. Anonymous users2024-01-31

    Actually, I want to see your loop body, if you give this information, j goes back to 0 to continue the loop, it's really puzzling, I understand the C51 single-chip microcomputer, using the standard C, so I suspect that the problem is in the loop body, not the interpreter.

  12. Anonymous users2024-01-30

    If you don't have a break statement, you will definitely not be able to end the loop, so it will return to the situation of j=0, so it becomes an endless loop, and your constraint is j<5, so it is impossible to equal 5 after the for statement, if the constraint is changed to j<=5, you can output 5, add if(j>5) break after the for statement; This will automatically end the loop after the output of 5.

  13. Anonymous users2024-01-29

    This cycle is fine, it should be something else wrong with you!

    Look for it again! Can you upload your function body?

  14. Anonymous users2024-01-28

    If you set j to be less than 5, of course you won't include 5, and you won't be able to execute 5 at all. To change to j<6 or j<=5.

  15. Anonymous users2024-01-27

    Can you send the ** up to see it? I'm also learning about microcontrollers

Related questions
8 answers2024-05-13

Isn't it this one:

Sorry baby >>>More

4 answers2024-05-13

After compiling to local, the fornext and doloop loops (including all other loops) use the same local **. The main reason for the speed difference between cycles is the execution speed of the cycle body**. If the circulation is very short (or even none), then as it was said upstairs, it depends on the conditions for exiting the loop. >>>More

13 answers2024-05-13

The idiom of uprooting is a grammatical structure, both backing and leaving are verbs, and both well and hometown are objects, so it is a verb-object structure. >>>More

4 answers2024-05-13

If you think it's cool, you can ignore the rest

9 answers2024-05-13

The flower here refers to the flower cut out of gold leaf, which is a kind of makeup for ancient women, because the tin foil is mostly yellow, and over time people will call the woman dressed like this as the yellow flower girl. And most of the women dressed in this way are unmarried, so the yellow flower girl has also become the title of a single woman, this kind of dress originated in the Song Wu Emperor period, and there is an interesting story in it. <> >>>More