Write the syntax of for loop and while loop.
Answers
Answered by
14
Answer:
Syntax for for loop:
for (initialization ; condition ; increment / decrement ) {
statements; (Body of the loop)
}
Syntax for while loop:
while ( condition ) {
statements ( Body of the while loop) ;
increment/ decrement ;
}
examples:
Q. Print 1 to 10 using loop (in C++)
for loop:
Code:
for (int i = 1 ; i<=10 ; i++ ) {
cout<<" " <<i ;
}
for loop:
Code:
int i = 1;
while ( i<=10 ) {
cout<<" " <<i ;
i++ ;
}
If you have doubt then let me know and I will try to clarify your doubts.
Please follow me and mark this ans as Branliest answer.Thank you!
Similar questions