如何编写While循环

时间:2020-03-05 18:47:14  来源:igfitidea点击:

如何编写While循环的语法?

C

int i = 0; 
while (i != 10)
{ 
   Console.WriteLine(i); 
   i++; 
}

VB.Net

Dim i As Integer = 0
While i <> 10
    Console.WriteLine(i)
    i += 1
End While

的PHP

<?php
while(CONDITION)
{
//Do something here.
}
?>

<?php
//MySQL query stuff here
$result = mysql_query($sql, $link) or die("Opps");
while($row = mysql_fetch_assoc($result))
{
$_SESSION['fName'] = $row['fName'];
$_SESSION['lName'] = $row['lName'];
//...
}
?>

Python

i = 0
while i != 10:
    print i
    i += 1

解决方案

回答

在PHP中,while循环将如下所示:

<?php
while(CONDITION)
{
//Do something here.
}
?>

一个现实的例子可能是这样的

<?php
//MySQL query stuff here
$result = mysql_query($sql, $link) or die("Opps");
while($row = mysql_fetch_assoc($result))
{
$_SESSION['fName'] = $row['fName'];
$_SESSION['lName'] = $row['lName'];
//...
}
?>

回答

此类问题可能会存在,但前提是答案是正确的。 "虽然"不是C#中的关键字。 while是。同样,!!和=之间的空格也是无效的。尝试:

int i=0; 
while (i != 10)
{ 
    Console.WriteLine(i); 
    i++; 
}

当我在这里时,Python:

i = 0
while i != 10:
    print i
    i += 1

回答

TCL

set i 0
while {$i != 10} {
    puts $i
    incr i
}

C ++,C,JavaScript,Java和许多其他类似C的语言都看起来与C#完全相同,除了它们将输出写入控制台的方式,或者可能是我们创建变量" i"的方式。回答那将属于其他问题。