Re-writing a loop

How would I re-write this for loop as a while loop?
1
2
3
4
5
 int i = 1;
 int s = 0; 

for (i = 1; i <= 10; i++) 
s = s + i;
1
2
3
4
while (i <= 10){
    s = s + i;
    i++;
}
Thanks! How about re-writing this While loop into a for loop? I'm currently studying for a quiz and wasn't really sure on these.

1
2
3
4
5
6
7
int s = 0; 

while (s <= 10) {
cout << s << “  “; 
s = s + 1;
}
Last edited on
1
2
for (s = 0; s <= 10; s++)
    cout << s << "  ";
Thanks, your help is very much appreciated!
Topic archived. No new replies allowed.