Question: When using loops in a program it is important to have 1 ) A condition that can actually be reached, and 2 ) If in
When using loops in a program it is important to have A condition that can actually be reached, and If in a for loop, incrementation.
If you have a while loop that exits the loop when active false, somewhere in the loop there must be a conditional statement that will make active false, otherwise you will be stuck in an infinite loop and crash your program. In a for loop if your loop does not iterate properly you will also create an infinite loop for int i ; i ; i will never exit since i is always going to be greater than or equal to the proper condition to check for would be i and decrement to
Two loops that you will see in many programs are the while loop and the for loop. A while loop can be used to loop through code while a condition is true. If you are writing a game, you would use a while loop to update every input or frame, depending on what kind of game you are making. A for loop increments through a quantity. So if you wanted to check for spaces in a string you could create a for loop that increments through every character in the string that looks for character a space character and run some code when that condition is met.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
