vb programming for loops turns out why there is no x 2

Updated on technology 2024-02-09
22 answers
  1. Anonymous users2024-02-05

    The data is stored in binary form in the computer, the decimal integer can be accurately converted to binary form, and there will be an error when the decimal number of the non-integer number is converted to a single-precision number or a double-precision number, and the non-integer number is used as a cyclic variable, and the step is also a non-integer number, so the number of cycles may not be as desirable. Therefore, you should avoid using non-integer numbers to control the loop.

    If you have to use it this way, you can change the 2 in this example to be much smaller than step) For decimal loop variables, it can also be done in a flexible way for the accuracy of the results:

    private sub command1_click()for x = 11 to 20 step 1r = x / 10 *

    a = (r - / (r + 1)

    print r; a; x / 10

    next x

    end sub

  2. Anonymous users2024-02-04

    When x 2, the cycle has ended.

    For is to judge first, then run the loop, if you want to run the loop first, and then judge whether it is over, you can use do--while loop

  3. Anonymous users2024-02-03

    Because you used step

    If you don't use this, it's just adding 1 each time

    That's what the grammar prescribes.

  4. Anonymous users2024-02-02

    for i = 1 to 4 'If you take the value of x, this i loop will not work, and the final result of 1 to 100 x will also be 7

    x = 2for j = 1 to 3' This j loop doesn't work x = 1

    for k = 1 to 2

    x = x + 3

    next k

    next j

    next i

    print x

    The above ** actually works is:

    x = 1for k = 1 to 2

    x = x + 3

    next k

    print x

    The result is 7

  5. Anonymous users2024-02-01

    Are you sure it's 11 when you print it out?

  6. Anonymous users2024-01-31

    step is the meaning of step, and step 2 is to skip a step. Originally, it was 1 2 3 4 5 6 7 8 9 10, and after step2 was executed, it was 1 3 5 7 9, and everything else was skipped.

    The whole execution step is on.

  7. Anonymous users2024-01-30

    Step 2 is to add 2 to i. The result is x 2+1+3+5+7+9 27

  8. Anonymous users2024-01-29

    for loop.

    for i=a to b step n

    where n is called the step size, and the cycle is from.

    The condition of the end is divided into two kinds of bai cases, one is the case of n>0, as long as the zhii+n>b cycle ends; The second is the case of n<0, as long as i+n in this dao, x=2+1+3+5+7+9=27

    If it is for i=10 to 1 step -2x=x+i

    next, then, x=2+10+8+6+4+2=32

  9. Anonymous users2024-01-28

    Please write that line ** clearly...

  10. Anonymous users2024-01-27

    It should be int((b-a)

    c+1) But this formula is inaccurate if there is a factor in the circulation body that changes the cyclic variable i. For example:

    fori=2

    to10step3if

    i<100

    theni=i+8

    nexti

  11. Anonymous users2024-01-26

    Total number of cycles = (10 - 2) 3 + 1 = 3

    i.e. i = 2, 5, 8, the step value is written by the programmer in the program and does not change with the number of cycles.

  12. Anonymous users2024-01-25

    1. The correct number of cycles should be:

    x = 0for i=a to b step c

    x = x + 1

    next i

    x is the total number of cycles.

    2. I think yours: "Total number of cycles = (b - a) c + 1" should be, for example:

    Total number of cycles for i=1 to 10 step 3 = (10-1) 3+1=3+1=4.

    3. Again: "And how does the step value change with the number of cycles?" "In my opinion, the step size does not change, it is always the set step value, and what changes is the initial value of the cycle, i.e. .

    for i=a to b step c in i, 1, 4, 7, 10.

  13. Anonymous users2024-01-24

    Method 1:

    i1=0for i = 2 to 10 step 3i1=i1+1

    total number of next cycles = i1

    Method 2: for i = 2 to 10 step 3next

    Total number of cycles = (10 - 2) 3 + 1for i = 2 to 10 step 3 The step value is 258

  14. Anonymous users2024-01-23

    step-1 means that each step is minus 1, that is, the first time in the cycle is i=4, then i=3, i=2

    This is the sorting method known as the "bubble method", which can be understood like this:

    The outer loop means that several rounds of comparison are required, and 3 rounds of comparison are required to compare the 4 elements, so for i = 4 to 2 step -1.

    And the inner loop can be said like this:

    The first time is i=4, a(1) and a(2), a(2) and a(3), a(3) and a(4) are compared, and if it is found that the order is not right, the positions are swapped, so that after the inner loop, the largest element will "sink" to the last digit to become the new a(4).

    The second time is i=3, find the largest in the first three elements (since a(4) is already the largest in the previous cycle comparison, so you don't need to compare a(4) again, you can change your ** inner loop to for j = 1 to i-1), and sink it to the third position to become the new a(3). In the same way, the third time is to sort in the first two digits. In this way, when the cycle is over, the smallest element rises to the top step by step, like a blister of water.

    The inner loop of the yutuo5 brother upstairs is wrongly defined, it should be for j = 1 to i-1.

    We apologize for the fact that I have made several revisions after I published my reply due to my negligence. )

  15. Anonymous users2024-01-22

    Sorting cannot be done with just one layer of loops. For example, the array is:

    After one sort: 3214

    After the second time: 2134

    Three times later: 1234

  16. Anonymous users2024-01-21

    First of all, it's not okay to use only one layer, and when your data is very special, there may be two loops that are a kind of bubbling algorithm after the change.

    It should be better to change it to the following **.

    for i = 4 to 2 step -1for j = 1 to i

    if a(j) >a(j + 1) thent = a(j + 1)

    a(j + 1) = a(j)

    a(j) = t

    end if

    next j

    next i

  17. Anonymous users2024-01-20

    for i = 4 to 2 step -1

    It is an operation from 4 to 2, decreasing by 1 every time.

  18. Anonymous users2024-01-19

    i from 1 to 3, when i = 1, j = 1; When i=2, j goes from 1 to 2....k is when j=1 and k from 1 to 3; When j=2, k goes from 2 to 3....In this way, you can calculate that when i = 1, j takes the value of 1 and k is 1 to 3, and the total cycle is 3 times; When i=2, the value of j is 1 and 2, k is called 3 times when j is 1, and 2 times when j is 2, for a total of 5 cycles. When i=3, the value of j is taken and 3, and k is cycled 3 times when j is 1, 2 times when j is 2, and 1 time when j is 3, for a total of 6 cycles.

    The rent chaos is cycled 3+5+6 = 14 times

  19. Anonymous users2024-01-18

    As follows:

    for i=0 to 999 'The omission of step here indicates that the step size is 1 cyclic body. next i

    Instructions from 0 to 999, 1000 cycles.

    Another example: for i=20 to 0 step -2 loop. next i

    Instructions go from 20 to 0 in steps of -2 and cycle 10 times.

    The for statement is a loop statement, and it is in the format:

    for variable = initial value to final value step step size] loop body. next variable.

  20. Anonymous users2024-01-17

    for loop variable = initial value to final value [step is the step size, the default step size is 1].

    Loop body]exit for].

    next [Loop variable] [, Loop variable] ......

    Note: 1. There are multiple parameters in the for loop format, and the meanings of these parameters are as follows:

    1) Cycle Variables: Also known as "Cycle Control Variables", "Control Variables" or "Cycle Counters". It is a numeric variable.

    2) Step size: cannot be 0. If the step size is 1, it can be omitted.

    3) The initial value, final value, and step size in the format are numeric expressions, but their values are not necessarily integers, they can be real numbers, and vb is automatically adjusted.

    2. The execution process of the for loop statement is: firstly, assign the "initial value" to the "loop variable", then check whether the value of the "loop variable" exceeds the final value, if it exceeds, stop the execution of the "loop body", jump out of the loop, and execute the statement after next, otherwise execute the "loop body" once, and then assign the value of "loop variable + step size" to the "loop variable", and repeat the above process.

    3. In VB, the for-next loop follows the principle of "check first, then execute", that is, check whether the loop variable exceeds the final value first, and then decide whether to execute the loop body. Therefore, when the step size is positive, but the initial value is final, or the step size is negative, but the initial value is final, the loop body will not be executed. When the initial value is equal to the final value, the loop body is executed once, regardless of whether the step size is positive or negative.

    4. The for statement and the next statement must appear in pairs and cannot be used separately, and the for statement must precede the next statement.

    5. The number of cycles is determined by three factors: the initial value, the final value and the step size, and the calculation formula is:

    Number of cycles = int (final value - initial value) step size + 1

    6. The for-next loop can be used nested.

    7. Cyclic variables are used to control the cyclic process, which can be referenced and assigned in the circulatory body. When a cyclic variable is referenced in the circular, it is called an "operational variable", and a non-referenced cyclic variable is called a "formal variable". If the cyclic variable is used as the operating variable, when the number of circulating variables in the circulating body is large, it will affect the clarity of the program.

  21. Anonymous users2024-01-16

    for is a loop statement, which well embodies the three problems that should be paid attention to in the correct expression of the loop structure

    1. Initialization of control variables.

    2. Circulating conditions.

    3. Update the cycle control variables.

    for expression:

    Expression 1: It is generally an assignment expression that assigns an initial value to the control variable;

    Expression 2: relational expression or logical expression, loop control condition;

    Expression 3: Generally an assignment expression, which increases or decreases the amount of the control variable.

    Statements: Loops, compound statements must be used when there are multiple statements.

    The for statement is in the format of:

    for loop variable = initial value to final value [step step] step 2 i=i+2

    Loop Body] next [Loop Variable].

    Note: 1) When the step size is > 0.

    The condition for loop execution is: loop variable <= final value.

    2) When the step size is < 0.

    The condition for loop execution is: loop variable <= final value.

    If you want to force the exit for loop and no longer execute, use exit for.

    For example, after clicking the command button command1, many message boxes will pop up, the message content will be 1 at the beginning, and the message content will pop up at the end will be 100, and every time the message box pops up, the message content will be increased by 1. That is, 1 starts to pop up, then 2, 3, 4 go back until 100 ends.

    vb ** as follows:

    private sub command1_click()dim i as long

    for i = 1 to 100

    msgbox i

    nextend sub

  22. Anonymous users2024-01-15

    The for loop in C is as follows:

    1. The simplest form of the sentence is:

    for( ;

    2. The general form is:

    for(single expression; conditional expressions; Terminal loop body).

    intermediate circulation body;

    Among them, the expression can be omitted, but the semicolon cannot be omitted, because "; It can represent an empty statement, and after omitting it, the statement is reduced, that is, the statement format changes, and the compiler cannot recognize it and cannot compile it.

    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.

    both"; The conditional expression is a relational expression, which 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 the intermediate loop has only one statement, the curly brace {} can be omitted, and the end loop [2] is executed after the middle loop body is executed.

    After executing the end loop body, the condition will be judged again, and if the condition is still true, the above cycle will be repeated, and when the condition is not true, the current for loop will be jumped.

Related questions
13 answers2024-02-09

Picturebox also works well

Generally, the graphics of each chess piece are collected in a single diagram. >>>More

25 answers2024-02-09

Is it because your mentality is not good? You have to know that what you do is what you do, and you do it with your conscience! Don't ask for anything in return! Have a grateful heart!! You'll be happy and don't feel like God is unfair.

8 answers2024-02-09

Hey: Understood.

Stuck in it at the beginning. >>>More

18 answers2024-02-09

Let's help you analyze it:

There are two reasons why the signal is not good: >>>More

16 answers2024-02-09

Occasional meditation to reflect on one's mind and understand the process of mind generation can go a long way in changing habits.