In general, access to data in List,array,set is accessed in the following wayint [] Nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, ten }; for (int i = 0; i ) { System.out.println ("i =" + i);}Since Java1.5, there has been a more convenient way to access: foreachint [] Nums = {1, 2, 3, 4, 5, 6, 7, 8, 9, ten }; for (int x:nums) { System.out.println ("Value is:" + x); + = x;}
Grammar:
For (type variable name: Collection variable name) {statements;}
Precautions
Do not perform the remove/add operation of elements in the Foreach loop. The remove element uses the Iterator method, which requires a lock on the Iterator object if the concurrency operation.
Positive example: iterator
while (Iterator.hasnext ()) {
String item = Iterator.next ();
If (delete element's condition) {
Iterator.remove ();
}
}
Counter example: list
List.add ("1");
List.add ("2");
for (String item
I recently bought php and mysql web development and saw the array loop statements. It is worth your attention and I will keep some handwriting for later reading.Generally, foreach uses more The code is as follows:Copy code $ Price = array ('apple' => 10, 'Orange '=> 20, 'banner' => 30 );Foreach ($ price as $ key => $ value) {Echo $ key
Namespace ConsoleApplication2{Class Program{//letter Letter Gigit digit Symbolstatic void Main (string[] args){Console.WriteLine ("Please enter character");string s = Console.ReadLine ();//input string is received with Sint letter = 0;//The initial number of letters is 0int gigit = 0; The number of first digits is 0int symbol = 0;//The number of first characters is 0foreach (char c in s)The {//foreach statement is used to iterate through the collectio
outputting the list as a string.
The top is an official document, look at it, for instance.Open= "(" close= ")" conjunction= "OR" >consultation_doctor_team_member_id = #[].consultation_doctor_team_member_id#and permission_id = #[].permission_id#1, prepend: The meaning of the prefix2, open= "(" close= ")" with parentheses in the meaning3. Conjunction: means filled with or4, consultation_doctor_team_member_id = #[].consultation_doctor_team_member_id#and permission_id = #[].permission_i
The first format is: for (element Type element variable: traversal Object) { executed code}For example:public class Test {public static void main (string[] Args) { //define an integer array, save score Information int[] scores = {89, 72, 64, 58, 93 }; Sorts the array of arrays classes Arrays.sort (scores); Use foreach to iterate through the elements in the output array for (int sco:scores) {System.out.println (sco);}}}He
of the stack -: IF_ICMPLT - //Compare the size of the value of the stack top two int, when the result is small at 0 o'clock Jump -:return //returns void from the current method}We only need to pay attention to the 6,16~23 line, we can find that the code is to take the value of the array reference copy in the top of the stack, and then take the variable from the top of the stack in the local variable 3, then put 55 on the top of the stack, and then 55 out of the local
top of the stack -: IF_ICMPLT - //Comparison of the size of the stack top two int type, when the result is small at 0 o'clock Jump -:return //returns void from the current method}We just need to focus on the 6,16~23 line. It is possible to find that the code is to take the value out of the array reference copy and place it on top of the stack, and then remove the variable from the top of the stack in local variable 3. Then put 55 on the top of the stack, and then put
Different types of loops
JavaScript supports different types of loops:For-loop code block a certain number of timesFor/in-Looping through the properties of an objectWhile-loops the specified code block when the specified condition is trueDo/while-also loops the specified code block when the specified condition is trueFor loopA For loop is a tool that you will of
JavaScript as the scripting language for the client, generally speaking, is the speed of the first. The speed required depends on what makes the fastest.
The circulation basically all language all has, is also the most commonly used, its embodiment, basically can represent the speed the embodiment.
Basically 2 loops in javascript: For loop while
The following small series will introduce you to the array traversal forEach () and map () methods in JavaScript and the compatible writing method. I think it is quite good. Now I will share it with you and give you a reference. Let's take a look at it with xiaobian.
• Principle:
• Advanced browsers support the forEach Method
Syntax: Both
I want to learn about the javascript for Loop and... in loops, which are objects that are iterated in JavaScript in two ways. This article will learn for loops and... if you are interested in the in loop, you will know that there are two methods to iterate objects in JavaScript
for IE support: Https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach if (! Array.prototype.forEach) {Array.prototype.forEach = function (callback, thisarg) {var T, K; if (this = null) {throw new TypeError ("This is a null or not defined"); } var O = Object (this); var len = o.length >>> 0; Hack to convert O.length to a UInt32 if
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.