Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+23 votes
asked in CSC211_Winter2018 by (1 point)
+1

A for loop looks like this for(int x=0; x<=10;x++) this is an example
1. Initialization is the initial condition which is executed once when the loop starts. Here, we can initialize the variable, or we can use an already initialized variable. It is an optional condition. int x=0 because that's the starting value
2. A condition must be met in order for the for loop to work. for example x<=10.
3. The last an incrementation/decrementation x++ or x--
The output 1,2,3,4,5,6,7,8,9,10
For loops makes you're coding more efficient and makes it more organized.

3 Answers

+13 votes

A for-loop is a coding loop that loops through a block of code a specific number of times.

I am unsure why it would be useful. However, maybe if you were working with limits or something.

Any help on why it would be useful?

answered by (1 point)
+12 votes

for-loops are very useful for when you have to repeat chunks of code a set amount of times. For example, in the last exercise on practiceIt for chapter 1, it asks to repeat a single line of code 1000 times. While this is a very tedious task using only static methods, it becomes extremely simple with for-loops.

answered by (1 point)
–3 votes

A for loop is a statement used to repeat the execution of a function for a fixed amount of time!

answered by (-499 points)
+4

A for loop looks like this for(int x=0; x<=10;x++) this is an example
1. Initialization is the initial condition which is executed once when the loop starts. Here, we can initialize the variable, or we can use an already initialized variable. It is an optional condition. int x=0 because that's the starting value
2. A condition must be met in order for the for loop to work. for example x<=10.
3. The last an incrementation/decrementation x++ or x--
The output 1,2,3,4,5,6,7,8,9,10
For loops makes you're coding more efficient and makes it more organized.

...