how to translate the for loop to do-while or while loop?

Write your question here.
guys can you translate this for nested in do-while or while loop.. thank you very much..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  #include<iostream>
using namespace std;

main(){
	
	
cout<<"multiplication table: "<< endl;
for(int num1=1; num1<=10; num1++){
	
	for(int num2=1; num2<=10; num2++){
		cout<<num1*num2<<"\t";
	}
	cout<<endl;
}
	
	
return 0;
	
	
}



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.
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
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
thank you very much..
Topic archived. No new replies allowed.