LEARN, PRACTICE & EXCEL!
What is the do-while syntax? Answer: do { body } while (condition);
When is do-while used? Answer: When loop must run at least once.
What is input validation? Answer: Ensuring user input is valid, often using loops.
Example of input validation? Answer: do { input = sc.nextInt(); } while (input <0);
What is sum of digits algorithm? Answer: sum=0; while(n>0){sum+=n%10; n/=10;}
What is divisibility test using digit sum? Answer: Divisible by 3 if digit sum divisible by 3.
What is a nested loop? Answer: A loop inside another loop.
Common uses of nested loops? Answer: Processing matrices, generating patterns, tables.
What is a multiple-subscripted variable? Answer: A variable that needs more than one index,
like 2D arrays.
What is a two-dimensional array? Answer: Array of arrays; declared int[][] arr=new int[r][c];
How access element in 2D array? Answer: arr[row][col]
What is row-major order? Answer: Rows stored sequentially in memory (Java).
What is column-major order? Answer: Columns stored sequentially (Fortran).
What is enhanced for loop? Answer: for(type var: array){ body }
When use enhanced for? Answer: When traversing all elements sequentially without modifying
indices.
Can enhanced for modify array? Answer: No, it only provides access to elements.
What is break in nested loop? Answer: Exits only innermost loop.
What is continue in nested loop? Answer: Skips to next iteration of innermost loop.
What is tuition forecast example? Answer: Start tuition, increase yearly until doubled; count
years.
What is outer loop in nested loop? Answer: The loop that contains another loop.
What is inner loop in nested loop? Answer: The loop inside another loop.
Order of execution in nested loops? Answer: Outer iteration triggers full set of inner iterations.
APPHIA – Crafted with Care and Precision for Academic Excellence.
1