Programming loopss Flashcards
(15 cards)
What are the three main types of loops?
- For loop
- While loop
- do while loop
What are the 2 types of loop situations?
- Indeterminate
- Determinate
What is an Indeterminate loop situation?
- A situation where we don’t know in advance how many times we may have to repeat or iterate a loop body code.
- Usually a while or do while loop is used in this scenario
What is a determinate loop situation?
- We know ahead of time exactly how many iterations our loop body code has to do.
- Usually a for or a counter controlled loop is used in this scenario
What happens in a while loop?
- The loop continuation condition is checked (The brackets next to the while loop) before trying to run the loop body statement.
- You need to include some information in the loop body that will eventually cause the condition to be false so that we can exit the loop.
What is a do- while loop?
- A do while loop will always run at least once before the condition is checked
- Often used as a data validation loop
What is the difference between break and continue?
- The continue keyword will stop the current iteration of the loop whereas break will exit the loop completely
What are the steps in creating a for loop?
- ) Set initial conditions for the loop and create the loop control variable
- ) Specify the conditions for the loop to continue. The brackets next to it aka the LCC
- ) Arrange it so that the loop control variable is incremented after each iteration of the loop
What is an array?
- A names set of contiguous memory cells
- Can be used to store both primitive and object data
What indexing do arrays use?
- Arrays use zero based indexing. The first value in the array always starts at zero
Can data types be mixed in the elements of an array?
- No
The operator used in creating the array is the square brackets []. What is another name for this?
- Array Index Operator
What is an array classified as in java
- Arrays are objects in Java
Instantiation gives values to the array. Once created can the array size change?
- Array size is fixed and cant be changed once created
Arrays are Homogeneous. What does this mean?
- Means they can only store one type of data