sql语句中的in用法示例

循环 (Loops)

Imagine that we need a program that says "hello world" 100 times. It's quite stressful and boring to write the statement -- echo "hello world" — 100 times in PHP. This is where loop statement facilitates the work for us.

想象一下,我们需要一个说“ hello world” 100次的程序。 编写该语句非常无聊,很无聊-echo“ hello world” -在PHP中是100次。 这是循环语句为我们简化工作的地方。

A loop statement is a statement that execute as long as a particular condition is valid and stops when that condition is invalid.

循环语句是只要特定条件有效就执行的语句,并在该条件无效时停止执行

Let's look at the different loops in PHP.

让我们看一下PHP中的不同循环

1)while循环 (1) The while loop)

The while statement executes a particular block of code as long as a statement remains true.

只要一条语句保持为truewhile语句就会执行特定的代码块。

Syntax:

句法:

    while (condition true) {
code to be executed;
}

Example:

例:

We want to display the number 1 to 5.

我们要显示数字1到5。

<?php
$x = 1;
while ($x <= 5) {echo "Number is: $x <br>";
$x++;
}
?>

Output

输出量

Number is :1
Number is :2
Number is :3
Number is :4
Number is :5

2)do ... while循环 (2) The do...while loop)

The do...while loop is the same as the while loop but for that it executes your code atleast once even if the condition is false before checking the condition to true and continues executing as the statement remains true.

do ... while循环while循环相同,但是do ... while循环即使条件为false也会至少执行一次代码,然后再将条件检查为true并继续执行,因为语句保持为true

Syntax:

句法:

    do {
code to be executed;
} while (condition is true);

Example:

例:

In this example we will repeat the example above but demonstrate how the do..while loop executes your code atleast once whether true or false before checking the condition.

在此示例中,我们将重复上面的示例,但演示在检查条件之前do..while循环如何至少一次执行您的代码,无论是true还是false。

<?php
$x = 1;
do {echo "Number is: $x <br>";
$x++;
} while ($x >= 5);
?>

Output

输出量

Number is :1

3)for循环 (3) The for loop)

The for loop works as the while loop but a difference in syntax, in this loop all the things like counter initialization, condition, increment and decrement statements are placed together separated by the semicolon.

for循环用作while循环,但在语法上有所不同,在该循环中,将计数器初始化,条件,递增和递减语句之类的所有内容放在一起,并用分号隔开。

Syntax:

句法:

    for (initialization counter; test counter; increment/decrement  counter) {
code to be executed;
}

The initialization counter is used to set the initial value.

初始化计数器用于设置初始值。

Test counter or condition determines the execution process, if true the loop continues if false the loop stops.

测试计数器或条件确定执行过程,如果为true,则循环继续;如果为false,则循环停止。

The increment/decrement counter, used to increments or decrements the initial value.

递增/递减计数器 ,用于递增或递减初始值。

Example:

例:

We go with our example again listing numbers from 1 to 5 with the for loop

我们再次使用示例,使用for循环列出从1到5的数字

<?php
for ($x = 1;$x <= 5;$x++) {echo "Number is: $x <br>";
}
?>

Output

输出量

Number is :1
Number is :2
Number is :3
Number is :4
Number is :5

翻译自: https://www.includehelp.com/php/loop-statements.aspx

sql语句中的in用法示例

sql语句中的in用法示例_PHP中的循环语句和示例相关推荐

  1. Java黑皮书课后题第5章:*5.18(使用循环语句打印4个图案)使用嵌套的循环语句,编写4个独立的程序打印下面的图案

    *5.18(使用循环语句打印4个图案)使用嵌套的循环语句,编写4个独立的程序打印下面的图案 题目 题目概述 破题 代码 题目 题目概述 *5.18(使用循环语句打印4个图案)使用嵌套的循环语句,编写4 ...

  2. c语言条件语句示例_PHP中的条件语句和示例

    c语言条件语句示例 PHP条件语句 (PHP Conditional Statements) While coding, you may get to a point where your resul ...

  3. python中until的用法_Shell脚本中循环语句for,while,until用法

    循环语句: Bash Shell中主要提供了三种循环方式:for.while和until. 一.for循环 for循环的运作方式,是讲串行的元素意义取出,依序放入指定的变量中,然后重复执行含括的命令区 ...

  4. C语言和Java中的while的区别_C语言while循环语句

    1.循环 只要达到指定条件,循环就可以执行代码块. 循环很方便,因为它们可以节省时间,减少错误并且使代码更具可读性. 2.C语言 while 循环 只要指定条件为true,while循环就会循环遍历一 ...

  5. linux中paste的用法,在Linux中使用Paste命令来合并行,包括使用Paste命令技巧及注意事项...

    在本文中,我们将教你如何使用Paste命令,包括使用Paste命令技巧及注意事项.Paste是允许你水平合并文件行的命令,它输出由指定为参数的每个文件的顺序对应的行组成的行,并用制表符分隔. 如何使用 ...

  6. C语言如何收集循环中的数,子数涵数·C语言——循环语句

    之前,我们讲过了编程中的三种结构(顺序.条件.循环),现在我们来看一下循环语句如何编写. 一.while循环语句(先判断后执行) 1 #include 2 int main(void) 3 { 4 i ...

  7. python所有for循环语句都可以用while改写_所有for循环语句都可以用while循环语句改写。...

    [判断题]Python使用缩进来体现代码之间的逻辑关系. (1.0分) [判断题]所有for循环语句都可以用while循环语句改写. (1.0分) [简答题]编写程序,计算并输出 1~100间所有奇数 ...

  8. matlab的循环语句裁图,[MATLAB图像处理] 多幅图片处理的循环语句

    多幅图片处理的循环语句 小弟毕业设计关于视频去雾处理,将视频截取为图片后对每张图片进行处理,其中需要用到循环语句来减少工作量,但自己对循环语句不怎么会,希望哪位大大能够给予帮助,谢谢了 程序如下 bl ...

  9. mysql中repair的用法_mysql8 参考手册--REPAIR TABLE语句

    REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLE tbl_name [, tbl_name] ... [QUICK] [EXTENDED] [USE_FRM] REP ...

最新文章

  1. Matlab心得及学习方法(不断更新)
  2. 制作模板_木模板制作流程
  3. 前后端同学,必会的Linux常用基础命令
  4. C++ 判断点是否在圆的内部
  5. 消息中间件和JMS介绍
  6. 递归 将一个整数逆序
  7. 快速的骆驼和云消息传递
  8. 本地同时修改2个版本
  9. 第 11 个“世界备份日”刚过,《Veeam 2021 数据保护报告》为你解读全球数据备份现状
  10. 技术优点_波纹管内衬管制造技术及优点
  11. mysql中条件查询加排序和索引的关系
  12. adb shell 命令之----pm
  13. <matplotlib.lines.Line2D object at 0x7f68cfd5a2e8>终极解决办法
  14. SharePoint 2010 中有个新的列表模板“导入电子表格”可以直接导入Excel数据并创建为列表 ....
  15. stl空间配置器alloc
  16. python大数据之数据分割(含k折交叉验证)
  17. PC网站实现微信扫码登录功能(一)
  18. 笔记44-JQuery高级笔记
  19. 抖音扫码跳转QQ群等外链源代码分享
  20. Git合并两个分支的步骤

热门文章

  1. unity 是厘米还是米_1种“竹节参”,植株有40厘米高,能挂果,果子成熟后变红,珍贵...
  2. Angularjs总结(五)指令运用及常用控件的赋值操作
  3. checkbox 最多选两项
  4. js原生带缩略图的图片切换效果
  5. (2017.9.27) 自定义列表项 list-style 使用心得
  6. Unity3D笔记十七 Unity3D生命周期
  7. 游戏大厅 从基础开始(6)--绕回来细说聊天室(中)之女仆编年史1
  8. Golang系列:打印命令行参数
  9. Python练习-迭代器-模拟cat|grep文件
  10. 网页性能优化(初窥)