Mar 18, 2014 at 5:33pm UTC
We're not a homework service. Have a go at writing the code. If you have problems with the code you've written, we'll help fix it.
If you understand how for loops work, and you understand how while loops work, then it's trivial to re-write one as the other. Try it.
Mar 20, 2014 at 2:25pm UTC
sorry if you miss understand what my post is all about..
im just confuse i tried to translate it to do-while or while statement.. but the output is wrong..
here are some of my experiment coding and my head is about to explode..
main(){
int a=1, b=1;
cout<<"Multiplication table: ";
do{
do{
cout<<a*b<<"\t";
b++;
}while(b<=10);
cout<<endl;
a++;
}while(a<=10);
but the output of this are unending looping displaying 4 4 4 4 4...
help please..
this is not a homework.. i just want to learn.. thank you..!!!
Last edited on Mar 20, 2014 at 2:26pm UTC
Mar 20, 2014 at 2:48pm UTC
while:
initialization
while (loop continuation condition )
{
code in loop
incremental statement (last statement in loop)
}
for:
for( initialization ; loop continuation condition ; incremental statement )
{
code in loop
}
This is generally how you can break down each part and where it fits in for loops and while loops. One big exception is how continue
behaves: in a while
loop it just goes back to check the continuation condition and starts the loop body over; in a for
loop it executes the incremental statement first and then checks the condition before starting the loop body again.
Last edited on Mar 20, 2014 at 2:48pm UTC