Js uses the for loop and if statement to determine multiple identical names, jsif

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.