for循环语句示例
for循环语句示例
一判断/var/目录下所有文件的类型
完整脚本
- [root@centos73 ~]# cat shell_scripts/filetype.sh
- #!/bin/bash
- #Author=wang
- RED="\033[31m"
- YELLOW="\033[0;33m"
- CYAN="\033[36m"
- PURPLE="\033[0;35m"
- RESET="\033[0m"
- if [ $# -ne 1 ] ; then
- echo -e "$RED you must enter a parameter$RESET"
- exit 1
- fi
- file=$1
- type=`ls -ld $file |cut -c 1`
- #使用case判断文件类型
- case $type in
- -)
- echo -e "$CYAN general file$RESET"
- ;;
- d)
- echo -e "$YELLOW dir$RESET"
- ;;
- l)
- echo -e "$PURPLE link file$RESET"
- ;;
- *)
- echo "other"
- ;;
- esac
执行结果
- [root@centos73 ~]# bash filetype.sh
- you must enter a parameter
- [root@centos73 ~]# bash filetype.sh /etc/passwd
- general file
- [root@centos73 ~]# bash filetype.sh /etc/
- dir
- [root@centos73 ~]# bash filetype.sh /etc
- dir
- [root@centos73 ~]# bash filetype.sh /bin/python
- link file
- [root@centos73 ~]# bash filetype.sh /bin/python
- link file
- [root@centos73 ~]# bash filetype.sh /bin/python
- link file
- [root@centos73 ~]# echo $PATH
- /root/shell_scripts:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
脚本解析
涉及到了颜色,相关知识参考博客给输出的字符或者字符串添加颜色
先判断参数,也就是文件是否存在
if [ $# -ne 1 ] ; then
echo -e "$RED you must enter a parameter$RESET"
exit
第1个参数赋值给变量
file=$
type=`ls -ld $file |cut -c 1`
- [root@centos73 ~]# ll -d /etc/passwd
- -rw-r--r--. 1 root root 2766 Jun 29 16:52 /etc/passwd
- [root@centos73 ~]# ll -d /etc/passwd | cut -c 1
- -
二/etc/rc.d/rc3.d目录下分别有多个以K开头和以S开头的文件
分别读取每个文件,以K开头的输出为文件加stop,以S开头的输出为文件名加start
如K34filename stop,S66filename start
完整脚本
- [root@centos73 shell_scripts]# cat file_KS.sh
- #!/bin/bash
- #Author=wang
- for i in `ls -1 /etc/rc.d/rc3.d` ; do
- type=`echo $i | cut -c 1 `
- if [ "$type" == "S" ] ; then
- echo "$i start"
- elif [ "$type" == "K" ] ; then
- echo "$i stop"
- else
- echo "$i unkown"
- fi
- done
- [root@centos73 shell_scripts]# ls -1 /etc/rc.d/rc3.d
- K50netconsole
- S10network
- [root@centos73 shell_scripts]# ls -1 /etc/rc.d/rc3.d | cut -c 1
- K
- S
执行结果
- [root@centos73 shell_scripts]# bash file_KS.sh
- K50netconsole stop
- S10network start
三提示输入正整数n的值,计算1+2+…+n的总和
完整脚本
- [root@centos73 shell_scripts]# cat sum.sh
- #!/bin/bash
- #Author=wang
- if [ $# -ne 1 ] ; then
- echo "you must enter a parameter"
- exit 1
- fi
- n=$1
- digit="^[0-9]+$"
- if [[ ! $n =~ $digit ]]; then
- echo "not a digit"
- exit 2
- fi
- declare -i sum=0
- #将变量定义为整形
- for i in `seq 1 $n`;do
- sum+=$i
- done
- echo $sum
执行结果
- [root@centos73 shell_scripts]# bash sum.sh 1
- 1
- [root@centos73 shell_scripts]# bash sum.sh 2
- 3
- [root@centos73 shell_scripts]# bash sum.sh 3
- 6
- [root@centos73 shell_scripts]# bash sum.sh 4
- 10
- [root@centos73 shell_scripts]# bash sum.sh 5
- 15
- [root@centos73 shell_scripts]# bash sum.sh 6
- 21
- [root@centos73 shell_scripts]# bash sum.sh 7
- 28
- [root@centos73 shell_scripts]# bash sum.sh 8
- 36
- [root@centos73 shell_scripts]# bash sum.sh 9
- 45
- [root@centos73 shell_scripts]# bash sum.sh 100
四打印九九乘法表
1*1=1
1*2=2 2*2=4
1*3=3 2*3=6 3*3=9
......
1*9=9 2*9 ... 9*9
要打印9行就要执行9次循环,第几行就循环几遍,第1行循环1遍,第9行循环9遍。
被乘数的值是从1到所在的行号,乘数就是所在行的行号。
完整脚本
- [root@centos73 shell_scripts]# cat nine_nine_multiplication_table.sh
- #!/bin/bash
- #Author=wang
- for ((i=1;i<=9;i++));do
- for ((j=1;j<=i;j++));do
- echo -ne "${j}x${i}=$[$i*$j]\t"
#\t表示插入tab。联系Linux可以使用tab键补齐,并且在文件里面输入tab键会退固定的空格- done
- echo
- done
执行结果
- [root@centos73 shell_scripts]# bash nine_nine_multiplication_table.sh
- 1x1=1
- 1x2=2 2x2=4
- 1x3=3 2x3=6 3x3=9
- 1x4=4 2x4=8 3x4=12 4x4=16
- 1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
- 1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36
- 1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49
- 1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64
- 1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81
脚本解析
使用for语句第2种语法,并且涉及到了两个变量
for ((i=1;i<=9;i++));do
for ((j=1;j<=i;j++));do
"${j}x${i}=$[$i*$j]\t" 因为x是字母,两个变量要使用花括号括起来
涉及到变量引用
变量引用:${name} $name
" ":弱引用,其中的变量引用会被替换为变量值
' ':强引用,其中的变量引用不会被替换为变量值,而保持原字符串
- [root@centos73 ~]# echo "{a}"
- {a}
- [root@centos73 ~]# echo "${a}"
- 1
- [root@centos73 ~]# echo ${a}
- 1
- [root@centos73 ~]# echo '${a}'
- ${a}
不合格脚本,原因在于没有tab键
- [root@centos73 shell_scripts]# cat nine_nine_multiplication_table.sh
- #!/bin/bash
- #Author=wang
- for ((i=1;i<=9;i++));do
- for ((j=1;j<=i;j++));do
- echo -ne "${j}x${i}=$[$i*$j]"
- done
- echo
- done
- [root@centos73 shell_scripts]# bash nine_nine_multiplication_table.sh
- 1x1=1
- 1x2=22x2=4
- 1x3=32x3=63x3=9
- 1x4=42x4=83x4=124x4=16
- 1x5=52x5=103x5=154x5=205x5=25
- 1x6=62x6=123x6=184x6=245x6=306x6=36
- 1x7=72x7=143x7=214x7=285x7=356x7=427x7=49
- 1x8=82x8=163x8=244x8=325x8=406x8=487x8=568x8=64
- 1x9=92x9=183x9=274x9=365x9=456x9=547x9=638x9=729x9=
五在/testdir目录下创建10个html文件,
文件名格式为数字N(从1到10)加随机8个字母
在/testdir目录下创建10个html文件,文件名格式为数字N(从1到10)加随机8个字母,如:1AbCdeFgH.html
完整脚本
- [root@centos73 shell_scripts]# cat randhtml_1.sh
- #!/bin/bash
- #Author=wang
- dir=/testdir
- if [ ! -d $dir ] ; then
- mkdir -pv $dir &>/dev/null
- fi
- for i in `seq 1 10` ; do
- rand=`openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8`
- touch $dir/$i$rand.html
- done
执行结果
- [root@centos73 shell_scripts]# bash randhtml_1.sh
- [root@centos73 shell_scripts]# ls /testdir/
- 10DtiEyzsk.html 2htpVNwja.html 4ysrokezy.html 6bPaFMedz.html 8hJRPmQxQ.html
- 1TUWVBvMC.html 3YtFXYSZm.html 5COTAQDfG.html 7RqvJatMs.html 9xnGiosvG.html
- [root@centos73 shell_scripts]# ls /testdir/ -l
- total 0
- -rw-r--r--. 1 root root 0 Jul 1 08:58 10DtiEyzsk.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 1TUWVBvMC.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 2htpVNwja.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 3YtFXYSZm.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 4ysrokezy.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 5COTAQDfG.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 6bPaFMedz.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 7RqvJatMs.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 8hJRPmQxQ.html
- -rw-r--r--. 1 root root 0 Jul 1 08:58 9xnGiosvG.html
脚本解析
- [root@centos73 ~]# openssl rand -base64 10
- 9HlYaAoiWqYhHQ==
- [root@centos73 ~]# openssl rand -base64 10
- hhT85PKosPFIrQ==
- [root@centos73 ~]# openssl rand -base64 10
- cZW6W01bbEHAlA==
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@g"
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@g"
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@g"
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@g"
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@gp"
- nKBMSLAnpyMg
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@gp"
- sSXTbVqzYQ
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@gp"
- MVCoWaDCmjcw
- [root@centos73 ~]# openssl rand -base64 10 |sed -rn "s@[^[:alpha:]]@@gp"
- guLpqstbTJw
- [root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8
- CJDYqHkQ[root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8
- VesypmUO[root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8
- hySmdYup[root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8
- gKzXWLKl[root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8
- ZxfSnlmE[root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8 | wc
- 0 1 8
- [root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8 | wc
- 0 1 8
- [root@centos73 ~]# openssl rand -base64 10 | sed -rn "s@[^[:alpha:]]@@gp"|head -c 8 | wc
- 0 1
六使用循环嵌套打印矩形
完整脚本
- [root@centos73 shell_scripts]# cat rectangle.sh
- #!/bin/bash
- #Author=wang
- line=10
- colume=8
- for i in `seq 1 $line ` ;do
- for j in `seq $colume`;do
- echo -e "*\c"
- done
- echo
- #执行完一次循环要换行,要执行10次循环就会换10行
- done
执行结果
- [root@centos73 shell_scripts]# bash rectangle.sh
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
要加反引号
下面是做10遍循环,人为的写上8个*
- [root@centos73 shell_scripts]# bash rectangle.sh
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- [root@centos73 shell_scripts]# bash rectangle.sh | wc
- 10 10 90
- [root@centos73 shell_scripts]# cat rectangle.sh
- #!/bin/bash
- #Author=wang
- line=10
- colume=8
- for i in `seq 1 $line ` ;do
- echo "********"
- done
脚本解析
如果是嵌套循环,最外层是打印10行,也就是先打印10行。
要调用两个变量,使用脚本里面常用的i,j,k
使用j表示来调用列,完成8个*的打印
因为*默认是换行的,\c就是压缩掉换行
先执行最外面循环,执行i=1,再执行里面的for循环,也就是打印一行的8个*
在循环体的最后一行 echo表示执行完一次循环要换行,要执行10次循环就会换10行
这个示例比较难理解
- [root@centos73 shell_scripts]# bash rectangle.sh
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- ********
- [root@centos73 shell_scripts]# vim rectangle.sh
- [root@centos73 shell_scripts]# man echo
- [root@centos73 shell_scripts]# cat rectangle.sh
- #!/bin/bash
- #Author=wang
- line=10
- colume=8
- for i in `seq 1 $line ` ;do
- for j in `seq $colume`;do
- echo -e "*\c"
- done
- echo
- #执行完一次循环要换行,要执行10次循环就会换10行
- done
bug1:
- [root@centos73 shell_scripts]# bash rectangle.sh
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- .......
- [root@centos73 shell_scripts]# cat rectangle.sh
- #!/bin/bash
- #Author=wang
- line=10
- colume=8
- for i in `seq 1 $line ` ;do
- for j in `seq $colume`;do
- echo "*"
- done
- echo
- done
echo打印的是空行
- [root@centos73 ~]# echo
- [root@centos73 ~]# echo
- [root@centos73 ~]# echo
- [root@centos73 ~]# echo | wc
- 1 0
bug2:
- [root@centos73 shell_scripts]# cat rectangle.sh
- #!/bin/bash
- #Author=wang
- line=10
- colume=8
- for i in `seq 1 $line ` ;do
- for j in `seq $colume`;do
- echo "*"
- done
- done
- [root@centos73 shell_scripts]# bash rectangle.sh
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
七打印三角形,要求行号和所在行的*个数相同
*
**
***
****
完整脚本
- [root@centos73 shell_scripts]# cat triangle.sh
- #!/bin/bash
- #Author=wang
- line=8
- for i in `seq $line`;do
- for j in `seq $i`;do
- echo -e '$\c'
- #\c表示最后不加上换行符合
- done
- echo
- done
执行结果
- [root@centos73 shell_scripts]# bash triangle.sh
- $
- $$
- $$$
- $$$$
- $$$$$
- $$$$$$
- $$$$$$$
- $$$$$$$$
脚本解析
变量i的值就是行号,这是默认的
for j in `seq $i`表示的是从1循环到行号
八打印等腰三角形
*
***
*****
完整脚本
- [root@centos73 shell_scripts]# cat isoscelestriangle.sh
- #!/bin/bash
- #Author=wang
- #num=总行号 i=第几行 j=*个数 k=空格个数
- read -p "请输入一个数字: " num
- #每行的空格数,以确定*的开始位置
- for i in `seq 1 $num`;do
- for k in `seq 1 $[$num-$i]`; do
- echo -n " "
- #-n表示换行,并且光标移至行首
- done
- #每行*的个数
- for j in `seq 1 $[2*$i-1]`;do
- echo -n "*"
- done
- echo
- done
- #删除变量
- unset num i j k color
执行结果
- [root@centos73 shell_scripts]# bash isoscelestriangle.sh
- 请输入一个数字: 4
- *
- ***
- *****
- *******
- [root@centos73 shell_scripts]# bash isoscelestriangle.sh
- 请输入一个数字: 52
- *
- ***
- *****
- *******
- *********
- ***********
- *************
- ***************
- *****************
- *******************
- *********************
- ***********************
- *************************
- ***************************
- *****************************
- *******************************
- *********************************
- ***********************************
- *************************************
- ***************************************
- *****************************************
- *******************************************
- *********************************************
- ***********************************************
- *************************************************
- ***************************************************
- *****************************************************
- *******************************************************
- *********************************************************
- ***********************************************************
- *************************************************************
- ***************************************************************
- *****************************************************************
- *******************************************************************
- *********************************************************************
- ***********************************************************************
- *************************************************************************
- ***************************************************************************
- *****************************************************************************
- *******************************************************************************
- *********************************************************************************
- ***********************************************************************************
- *************************************************************************************
- ***************************************************************************************
- *****************************************************************************************
- *******************************************************************************************
- *********************************************************************************************
- ***********************************************************************************************
- *************************************************************************************************
- ***************************************************************************************************
- *****************************************************************************************************
- *******************************************************************************************************
脚本解析
打印几行那么第1行的第1个内容,比如*就处在第几列
每行的*的个数与行号的关系:2n-1
每行的空格数和行数的关系:总行数-行数
循环的次数和行数一样。
主要是逻辑思维
line=3
for i in `seq 1 total`
do
for j in ;do
空格数=total-n
*数=2n-1
done
echo
done
不合格脚本
- [root@centos73 shell_scripts]# cat isoscelestriangle.sh
- #!/bin/bash
- #Author=wang
- #num=总行号 i=第几行 j=*个数 k=空格个数
- read -p "请输入一个数字: " num
- #每行的空格数,以确定*的开始位置
- for i in `seq 1 $num`;do
- for k in `seq 1 $[$num-$i]`; do
- echo " "
- #-n表示换行,并且光标移至行首
- done
- #每行*的个数
- for j in `seq 1 $[2*$i-1]`;do
- echo "*"
- done
- echo
- done
- #删除变量
- unset num i j k color
- [root@centos73 shell_scripts]# bash isoscelestriangle.sh
- 请输入一个数字: 4
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
- *
九打印国际象棋
国际象棋是8行8列
打印有颜色的格子
打印颜色参考博客https://www.cnblogs.com/wang618/p/11047178.html
- [root@centos73 shell_scripts]# echo -e ' \033[41m \033[0m '
- [root@centos73 shell_scripts]# echo -e ' \033[43m \033[0m '
- [root@centos73 shell_scripts]# echo -e ' \033[43m \033[0m '; echo -e ' \033[41m \033[0m '
- [root@centos73 shell_scripts]# echo -e ' \033[41m \033[0m '; echo -e ' \033[43m \033[0m '
- [root@centos73 shell_scripts]# echo -e ' \033[41m \033[0m '
- [root@centos73 shell_scripts]# echo -e '\033[41m \033[0m\c '; echo -e '\033[43m \033[0m '
- [root@centos73 shell_scripts]# echo -e '\033[41m \033[0m\c '; echo -e '\033[43m \033[0m '
- [root@centos73 shell_scripts]# echo -e '\033[41m \033[0m\c '; echo -e '\033[43m \033[0m ';
echo -e '\033[41m \033[0m\c '; echo -e '\033[43m \033[0m '
法1完整脚本
写死了,不能交互,只能打印8个格子
- [root@centos73 shell_scripts]# cat Chess.sh
- #!/bin/bash
- #Author=wang
- line=8
- line2=$[line*2]
- #打印格子和颜色有关,因为只涉及两种颜色,五五开
- #i是打印格子的数量,j是循环次数
- #从里到外进行循环,最里面是循环最前面的两个格子
- for i in `seq 1 8 ` ; do
- for j in `seq 1 $line2 ` ; do
- if [ $[i%2] -eq 1 ] ; then
- if [ $[j%4] -eq 1 -o $[j%4] -eq 2 ] ; then
- echo -ne "\033[41m \033[0m"
- else
- echo -ne "\033[42m \033[0m"
- fi
- else
- if [ $[j%4] -eq 1 -o $[j%4] -eq 2 ] ; then
- echo -ne "\033[42m \033[0m"
- else
- echo -ne "\033[41m \033[0m"
- fi
- fi
- done
- echo
- done
执行结果
脚本解析
使用了if语句的嵌套
法2完整脚本
- [root@centos73 shell_scripts]# cat Chess_1.sh
- #!/bin/bash
- #Author=wang
- read -p "please input NUM : " num
- #交互式输入数字,这样更灵活
- for i in $(seq 1 $num)
- #输入的数字作为变量值
- do
- j=$[i%2]
- #j是取模值,和颜色有关,为0为1颜色相反
- times=$[num/2]
- #决定每行打印格子的次数,因为两种颜色有交替,那么就是要经过(打印格子数/2)次循环
- case $j in
- 0)
- for times in $(seq 1 $times)
- do
- echo -e '\033[47m \033[0m\c'
- echo -e '\033[45m \033[0m\c'
- done
- echo -e ""
- ;;
- 1)
- for times in $(seq 1 $times)
- do
- echo -e '\033[45m \033[0m\c'
- echo -e '\033[47m \033[0m\c'
- done
- echo -e ""
- ;;
- esac
- #case嵌套了for循环
- done
执行结果
脚本解析
read -p "please input NUM : " num交互式输入数字,这样更灵活
变量i是执行循环的次数,变量j决定了每个格子的颜色
对j取模来决定一行前面两个格子的颜色。
如果取模的值是0就是白紫,如果取模的值是1那么就是紫白,
上面执行脚本的时候反应慢是因为嵌套循环多了,如果每行每列打印8个格子,那么要经过4次循环。
如果是随机打印格子,那么要经过(打印格子数/2)次循环。
注意echo -e ""是必不可少的。
作用是每打印一行就空一行,这样不会粘在一起,全部内容打印到同一行
- [root@centos73 shell_scripts]# echo aa
- aa
- [root@centos73 shell_scripts]# echo aa | wc
- 1 1 3
- [root@centos73 shell_scripts]# echo aa;echo -e ""
- aa
- [root@centos73 shell_scripts]# echo aa;echo -e "" | wc
- aa
- 1 0
没有添加echo -e ""
- [root@centos73 shell_scripts]# cat Chess_1.sh
- #!/bin/bash
- #Author=wang
- read -p "please input NUM : " num
- #交互式输入数字,这样更灵活
- for i in $(seq 1 $num)
- #输入的数字作为变量值
- do
- j=$[i%2]
- #j是取模值,和颜色有关,为0为1颜色相反
- times=$[num/2]
- #决定每行打印格子的次数,因为两种颜色有交替,那么就是要经过(打印格子数/2)次循环
- case $j in
- 0)
- for times in $(seq 1 $times)
- do
- echo -e '\033[47m \033[0m\c'
- echo -e '\033[45m \033[0m\c'
- done
- # echo -e ""
- ;;
- 1)
- for times in $(seq 1 $times)
- do
- echo -e '\033[45m \033[0m\c'
- echo -e '\033[47m \033[0m\c'
- done
- # echo -e ""
- ;;
- esac
- #case嵌套了for循环
- done
for循环语句示例的更多相关文章
- for循环语句示例应用
age = 22 #优化前 ''' for i in range(10): guess_num = int(input('input your guess num:')) if guess_num = ...
- Shell循环语句for、while、until
Shell循环语句for.while.until 一.条件测试 二.删除字符 三.循环语句 示例1 ...
- python之最强王者(3)——变量,条件、循环语句
1.Python 变量类型 变量存储在内存中的值.这就意味着在创建变量时会在内存中开辟一个空间. 基于变量的数据类型,解释器会分配指定内存,并决定什么数据可以被存储在内存中. 因此,变量可以指定不同的 ...
- JavaScript 的循环语句语法摘要
if条件语句语法: if(condition){ statements; } 理解:圆括号里的是条件参数 ,花括号里的为执行的语句. 示例代码:if(1>2){ alert("Th ...
- 04- Shell脚本学习--条件控制和循环语句
条件判断:if语句 语法格式: if [ expression ] then Statement(s) to be executed if expression is true fi 注意:expre ...
- 你可能不知道的java、python、JavaScript以及jquary循环语句的区别
一.概述 java循环语句分为四种形式,分别是 while, do/while, for, foreach: python中循环语句有两种,while,for: JavaScript中循环语句有四种, ...
- 不可或缺 Windows Native (3) - C 语言: 运算符,表达式,条件语句,循环语句,转向语句,空语句等
[源码下载] 不可或缺 Windows Native (3) - C 语言: 运算符,表达式,条件语句,循环语句,转向语句,空语句等 作者:webabcd 介绍不可或缺 Windows Native ...
- python_条件、循环语句
1. python中语句块如何定义: 在Python中,冒号(:)用来标识语句块的开始,块中的每一个语句都是缩进的.当回退到和已经闭合的块一样的缩进量时,就表示当前块已经结束. 默认推荐缩进 ...
- JavaScript的循环语句
JavaScript的循环语句 1.JavaScript的循环语句 (1)for循环语句 - 循环代码块一定的次数: (2)for/in循环语句 - 循环遍历对象的属性: (3)while循环语句 - ...
随机推荐
- vue中路由传参的方式
一.params的类型: 配置路由格式: /router/:id 传递的方式: 在path后面跟上对应的值 传递后形成的路径: /router/123, /router/abc 通过:to字符串拼接的 ...
- ckeditor实现WORD粘贴图片自动上传
自动导入Word图片,或者粘贴Word内容时自动上传所有的图片,并且最终保留Word样式,这应该是Web编辑器里面最基本的一个需求功能了.一般情况下我们将Word内容粘贴到Web编辑器(富文本编辑器) ...
- nodejs环境安装
centos7安装nodejs环境 原文地址: https://www.cnblogs.com/MY0101/p/6625344.html 下载地址: https://nodejs.org/dist/ ...
- [CSP-S模拟测试]:gcd(莫比乌斯反演)
题目描述 有$n$个正整数$x_1\sim x_n$,初始时状态均为未选.有$m$个操作,每个操作给定一个编号$i$,将$x_i$的选取状态取反.每次操作后,你需要求出选取的数中有多少个互质的无序数对 ...
- linux6.5 RPM方式安装 mysql5.6
步骤一.检查下linux是不是已经安装了MySQL # rpm -qa|grep mysql mysql-libs-5.1.71-1.el6.x86_64 # rpm -e --nodeps mysq ...
- Django中的get()和filter()区别
前言 在django中,我们查询经常用的两个API中,会经常用到get()和filter()两个方法,两者的区别是什么呢? object.get()我们得到的是一个对象,如果在数据库中查不到这个对象或 ...
- 2016年Esri技术公开课全年资料分享
大家好,2016年的公开课活动在上周全部结束,感谢大家的支持. 2016年的公开课共进行20期,共有24位讲师参与,公开课视频播放.课件下载次数累计超10万次,在这里衷心的感谢大家的积极参与和分享精神 ...
- node js 操作redis promise
连接 redis = require('redis') var client = redis.createClient('6379', '127.0.0.1'); client.on('connect ...
- MySQL-5.7填坑
绿色版(zip archive 版)无 my-default.ini As of MySQL 5.7.18, my-default.ini is no longer included in or in ...
- TestStack.White安装详解
一.安装 NuGet TestStack.White是通过NuGet进行安装的.NuGet最低支持VS2010.我使用的VS2015. 安装方式一 :从Visual Studio的工具->扩展和 ...