views:

937

answers:

8

How do you write the syntax for a While loop?

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
+3  A: 

What exactly is your question?

Thomas Owens
+2  A: 
while (Poster == Karma.Fisher)
{
    Console.WriteLine("Why are you doing this?");
}
FlySwat
+4  A: 

Umm... looks like you got it?

@Unkwntech - I didn't vote him down. I stand by my response, I'm a little befuddled by the fact that he asked a VERY basic question in the title and immediately answered it in the body.

swilliams
+5  A: 

@Thomas Owens & swilliams & everyone-who-voted-him-down - If you listen to ALL the podcasts you'll see that Jeff specificly mentions these types of questions, they are intended for the people learning the language.

@everyone Please dont vote him down for this there is a reason for these types of posts.

In PHP a while loop will look like this:

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

A real world example of this might look something like this

<?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'];
//...
}
?>
Unkwntech
There is a reason. Wow. I feel better now.
Daniel Daranas
+5  A: 

There may be a place for this type of question, but only if the answer is correct. While isn't a keyword in C#. while is. Also, the space between the ! and = isn't valid. Try:

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

While I'm here, Python:

i = 0
while i != 10:
    print i
    i += 1
Blair Conrad
+1  A: 

I personally disagree with these sorts of questions. This to me says rep "farming" or "seeding". You know the answer to this question, you didn't need to ask it.

Otherwise we should all just get working on a bot to read in the contents of the wikipedia comp sci and programming sections and start posting away!

This has now become a deadlocked post because you posted the answer in the question because you knew it, there is now no answer.

I have closed this question instead of downmodding it, hopefully that will save you some rep.

Rob Cooper
Have you? I just voted to close and the page tells me there is only one closing vote - mine.
Daniel Daranas
It's community wiki - shouldn't be farming much rep.
RodeoClown
Guys, check the age of this comment. It's 10 months old. Also, the post was made community wiki after it was closed by Rob.
Stephan202
Thanks Stephan, well pointed out ;)
Rob Cooper
+5  A: 

My thought on this kind of question is that you should post a question in the question field and the answer in the answer field. I think that's how SO is designed to function. Questions aren't answers.

Thomas Owens
A: 

TCL

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

C++, C, JavaScript, Java and a myriad of other C-like languages all look exactly the same as C#, except in the way that they write the output to the console, or possibly the way you create the variable i. Answering that would belong in some other question.

TokenMacGuy