当前位置:网站首页>A brief introduction to the for loop. Some of the code involves arrays
A brief introduction to the for loop. Some of the code involves arrays
2022-07-28 12:53:00 【Xiao Yang should work hard】
Basic format
!!for ( sentence 1; sentence 2; sentence 3) {
Block of code to execute
}
for Monolayer cycle
General writing :
document.write(cars[0] + "<br>");
document.write(cars[1] + "<br>");
document.write(cars[2] + "<br>");
document.write(cars[3] + "<br>");
document.write(cars[4] + "<br>");
document.write(cars[5] + "<br>");
Use for loop
for (var i=0;i<cars.length;i++) {
document.write(cars[i] + "<br>");
}
for loop
Grammatical structure :
for( Initialize variable ; Conditional expression ; Operation expression ){
// The loop body
}
give an example :
for (var i = 1; i <= 5; i++) {
console.log(' The number is :' + i + '\n');
}
Case study : Find the sum and average of an array ( Involving arrays )
var sum =[1,2,3,4,6,7,10]
var o =0;
var p = 0;
sum[3]=55;
for(var i=0;i<sum.length;i++){
o = o +sum[i]
console.log(sum[i])
}p = o/sum.lengthFind the maximum value of an array ( Involving arrays )
var arr = [10,5,6,9,4,5];
var i =arr[0];
var w =arr[0];
for(var o=0;o<arr.length;o++){
if(i<arr[o]){
i = arr[o]
}
}console.log(" Maximum "+i)Print inverted triangle
var i ="";
for(var k=1;k<=5;k++){
for(var q=1;q<=6-k;q++){
i = i + "*";
}
i = i +"\n";
}
console.log(i);Print a square
var str="";
for(var i=1;i<=4;i++){
for(var j=1;j<=4;j++){
str = str+"*";
}
str = str+"\n"
}
console.log(str);Print the multiplication table
var num= "";
for(var i=1;i<=9;i++){
for(var j=1;j<=i;j++){
num = num + j + "*" + i +"="+ j*i + "\t";
} num = num + "\n";
}console.log(num);边栏推荐
- Fundamentals of machine learning - support vector machine svm-17
- [base] what is the optimization of optimization performance?
- 上位机和三菱FN2x通信实例
- Custom paging tag 02 of JSP custom tag
- 连通块&&食物链——(并查集小结)
- 机器学习基础-支持向量机 SVM-17
- Multiple items on a computer share a public-private key pair to pull the Gerrit server code
- Four authentic postures after suffering and trauma, Zizek
- Deployment之滚动更新策略。
- The largest rectangle in leetcode84 histogram
猜你喜欢

Multiple items on a computer share a public-private key pair to pull the Gerrit server code

西门子对接Leuze BPS_304i 笔记
![[cute new problem solving] climb stairs](/img/a2/fd2f21c446562ba9f0359988d97efe.png)
[cute new problem solving] climb stairs

VS1003调试例程

DART 三维辐射传输模型申请及下载

Scala transformation, filtering, grouping, sorting

Summary: golang's ide:vscode usage

SuperMap iclient3d for webgl to realize floating thermal map

leetcode:704二分查找

Vs code is not in its original position after being updated
随机推荐
Sliding Window
Distributed session solution
SuperMap arsurvey license module division
[base] what is the optimization of optimization performance?
Ccf201912-2 recycling station site selection
04 pyechars geographic chart (example code + effect diagram)
C语言项目中使用json
Initialization examples of several modes of mma8452q
区块反转(暑假每日一题 7)
New Oriental's single quarter revenue was 524million US dollars, a year-on-year decrease of 56.8%, and 925 learning centers were reduced
Hongjiu fruit passed the hearing: five month operating profit of 900million Ali and China agricultural reclamation are shareholders
Leetcode 42. rainwater connection
20220728 common methods of object class
03 pyechars rectangular coordinate system chart (example code + effect drawing)
Jinshanyun rushes to the dual main listing of Hong Kong stocks: the annual revenue of 9billion is a project supported by Lei Jun
Cloud native - runtime environment
Communication example between upper computer and Mitsubishi fn2x
VS1003 debugging routine
01 pyechars 特性、版本、安装介绍
界面控件Telerik UI for WPF - 如何使用RadSpreadsheet记录或评论