how to convert one loop to another loop plz explain
Home
/
Computer Science
/
how to convert one loop to another loop plz explain
how to convert one loop to another loop plz explain
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Firstly I think that you are aware about the basic usage of loops i.e, repeating a task no matter what ever may be the task.
Now coming to your question
/* Let's say the task to be executed is printing god for 6 times in c programming*/
i=0;. // This is the initialisation of the loop
while (i<6) // condition
{
printf(“God”); // task
i++; / *incrementing the loop after the execution of task*/
}
A for loop template is as follows
for(initialisation; condition; increment/decrement)
{
Task;
}
Template reflects that inside a for only the task will be there nothing more than that so everything like condition and incrementing will be defined while writing the loop
for the same problem the execution using for loop is as follows
for(i=0;i<6;i++)
{
printf(“God”);
}