8

您如何编写 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
4

3 回答 3

5

在 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'];
//...
}
?>
于 2008-09-03T19:47:24.990 回答
5

这类问题可能会有一席之地,但前提是答案是正确的。While不是 C# 中的关键字。while是。此外, 和 之间的空格!无效=。尝试:

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

当我在这里时,Python

i = 0
while i != 10:
    print i
    i += 1
于 2008-09-03T19:50:45.497 回答
0

TCL

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

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

于 2009-07-15T23:43:16.433 回答