4
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Nick Evan
0

The condition in the while loop will be the same as the for loop, namely the count is less than 51. Then just display the current count, and then increment the count variable by one.
This snippet (which I wrote in c++) displays what I just said,

int count=1;
    for(count; count<51; count++)
    cout<<" "<<count;
    
    while(count<51)
    {
      cout<<" "<<count;
      count++;
    }

Both loops do the same thing. I think thats what you are looking for.

0

for count= 1 to 50
display count
End for

int count = 1;
while count < 51{
    display count;
    count = count + 1;
}

Edited by Nick Evan: Added code-tags

0
How do you for loop into a while loop??


But on a serious note (in C++ for example):

int outer = 0;
while (outer  < 10){
    for (int inner = 0; inner < 10; ++inner){
        cout << "outer: " << outer << " inner: " << inner << '\n';
    }
    outer++;
}

Edited by Nick Evan: n/a

Attachments 2824685.jpg 60.47 KB
0

Umm I might be confused but I just got three PMs from you (posted above me) and you just reiterated what two previous posters in here have already said. Was that really necessary?

0

Umm I might be confused but I just got three PMs from you (posted above me)

From me? I didn't send you anything.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.