answersLogoWhite

0

the for loop is basically a repitation or traversing loop means one's to write his name 100 times he use the for loop

example

for(i=0;i<=100;i++)

{

printf("my name is AA");

}

the for loop checks the condition until i<=100 repeates the name or check the condition upto 100 times and then terminates.

User Avatar

Wiki User

13y ago

Still curious? Ask our experts.

Chat with our AI personalities

JordanJordan
Looking for a career mentor? I've seen my fair share of shake-ups.
Chat with Jordan
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
More answers

A for loop is a loop of the form:

for (/*starting conditions/variable initialisation*/;/*condition*/;/*changes to variables*/) {}

The most basic example would be:

for (int i=0;i<10;i++) {

prinf("%i",i);

}

This code can be represented as the following algorithm:

  1. Let i=0
  2. If i>=10, go to step 6
  3. Write the value of i to the standard output stream
  4. Increment i (ie. i=i+1)
  5. Go to step 2
  6. End

The standard algorithm, for any 4 statements:

for (/*EXPRESSION 1*/;/*EXPRESSION 2*/;/*EXPRESSION 3*/) {

/*STATEMENT 4*/

}

would be:

  1. EXPRESSION 1
  2. If EXPRESSION 2 is false go to step 6
  3. STATEMENT 4
  4. EXPRESSION 3
  5. Go to step 2
  6. End
User Avatar

Wiki User

14y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is the algorithm for a for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp