Js uses the for loop and if statement to determine multiple identical names, jsif
Var items = document. getElementsByName ("spec_spec_1 []"); alert (items. length); for (I = 0; I <items. length; I ++) {if (items [I]. value = '') {alert ('name cannot be blank ');}}
Which of the following statements must be written in the second statement of the C language for loop?
The second statement contains an expression used to determine the condition.
In a for loop, you can use the comma operator to use multiple statements as a compound statement, all compound statements can be written to a place where only one statement can be written, such as in the if expression,
In the expression of the comma operator, only the last statement is used as the return value of this expression ..
For example:
Int I;
For (I = 0; I <0, I <5; I ++ ){
Printf ("% d", I );
}
Only I <5 is used as the condition, and I <0 is used only as a statement.
In C, all non-0 values are true, and only 0 values are false,
Even for (1; 1; 1) {} can be used, so j <k & j <10 is not a problem at all.
What are the advantages and disadvantages of the following programs? Program 1: Nested if and else statements in the for loop, Program 2: if and else statements nested for Loop
This question seems the same, but it is actually different. I think it should be compared in terms of time. program 2 wastes more time than program 1. The specific analysis is as follows: Here, dosomething is ignored as a semicolon ";"
Procedure 1:
If (k> 8) executes 100 times. else splits rows 100 times, that is, k <8 is 100 + 1 times at most
Procedure 2
For (100 times...) {if (...) else (...)}, that is, up to k <8 is 100*2 times
Obviously, Program 2 uses more time than program 1.
Of course, it is not possible to calculate the number of steps by assembly, but it is roughly like this.
You can try it on your computer.