U3: Loops
No description yet. This curated deck is ready for daily study.
Card preview (12)
Loops
• Allow programmer to see patterns in problems and write program accordingly • Limited code repeats infinitely
Infinite Loop
Loop that doesn’t stop (not good for program)
For Loop [A]
• Exists in wide variety of languages; works similarly in all • Has built-in variable keeping track of no. of loop executes
For Loop [B]
• Starts at certain number; ends at certain number • Can be incremented or decremented by given number
Purpose of For Loop
• When times loop needed to execute already known • When variable used to indicate no. of loop executes
While Loops
• Used when programmer doesn’t know no. of times loop needs to repeat • while; do while
“While” Loop
Used for executing loop +0 times
“Do While” Loop
Used for executing loop +1 times
System.out.print vs. system.out.println
• System.out.print prints in single line repeatedly • System.out.println prints in different lines repeatedly
How User Input Influences Loops
Can change no. of times loop executes; exit program
Data Structure
• Specific way to organize large amounts of same type of data • Can store, process and output data • Arrays, stacks, queues, linked lists
Nested Loops
Loops inside of loops