Computer Science, asked by prachich023, 7 months ago

for(i=6;i>8;i++) print i​

Answers

Answered by Anonymous
0

Answer:

That's a loop that says, okay, for every time that i is smaller than 8, I'm going to do whatever is in the code block. Whenever i reaches 8, I'll stop. After each iteration of the loop, it increments i by 1 (i++), so that the loop will eventually stop when it meets the i < 8 (i becomes 8, so no longer is smaller than) condition.

For example, this:

for (int i = 0; i < 8; i++)

{

Console.WriteLine(i);

}

Will output: 01234567

See how the code was executed 8 times?

In terms of arrays, this can be helpful when you don't know the size of the array, but you want to operate on every item of it. You can do:

Disclaimer: This following code will vary dependent upon language, but the principle remains the same

Array yourArray;

for (int i = 0; i < yourArray.Count; i++)

{

Console.WriteLine(yourArray[i]);

}

The difference here is the number of execution times is entirely dependent on the size of the array, so it's dynamic.

Similar questions