Bird
0
0

How can you modify a WHILE loop to skip inserting the number 3 into a table but insert all others from 1 to 5?

hard📝 Application Q9 of 15
SQL - Stored Procedures and Functions
How can you modify a WHILE loop to skip inserting the number 3 into a table but insert all others from 1 to 5?
AUse IF inside loop: IF @i != 3 INSERT ...
BChange loop condition to WHILE @i < 3
CRemove increment when @i = 3
DUse BREAK when @i = 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand skipping logic

    To skip 3, check inside loop and only insert if @i is not 3.
  2. Step 2: Evaluate options

    Use IF inside loop: IF @i != 3 INSERT ... uses IF condition to skip 3; others stop loop or skip increments incorrectly.
  3. Final Answer:

    Use IF inside loop: IF @i != 3 INSERT ... -> Option A
  4. Quick Check:

    Conditional insert skips specific value [OK]
Quick Trick: Use IF condition inside WHILE to skip specific values [OK]
Common Mistakes:
  • Changing loop condition excludes more than one value
  • Using BREAK stops entire loop
  • Removing increment causes infinite loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes