Pergunta

Como você escreve a sintaxe de um loop 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'];
//...
}
?>

Pitão

i = 0
while i != 10:
    print i
    i += 1
Foi útil?

Solução

Em PHP, um loop while ficará assim:

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

Um exemplo do mundo real disso pode ser algo assim

<?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'];
//...
}
?>

Outras dicas

Pode haver lugar para esse tipo de pergunta, mas somente se a resposta estiver correta. While não é uma palavra-chave em C#. while é.Além disso, o espaço entre os ! e = não é válido.Tentar:

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

Enquanto estou aqui, Pitão:

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

TCL

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

C++, C, JavaScript, Java e uma infinidade de outras linguagens semelhantes a C parecem exatamente iguais a C#, exceto na maneira como escrevem a saída no console, ou possivelmente na maneira como você cria a variável i.Responder a isso pertenceria a alguma outra pergunta.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top