Library › Coding AI › High school students
Trace a while loop one pass per line
Practice: Asking for a format you can use. About 5 minutes.
About this exercise
You're studying for a quiz on while loops. Ask for a trace of the program in exactly 3 numbered lines, one per pass, each like 'After pass 1: n = 10, count = 1', then one unnumbered line 'Prints: <what it prints>'. No code blocks and no explanation, under 50 words.
Common mistakes when you ask AI for this
- Getting an explanation. Asked to explain, the AI writes paragraphs about while loops instead of a trace you can check against yours. Try: Say: "Exactly 3 numbered lines, one per pass, no explanation."
- No line shape. Without an example, each line looks different and is hard to compare. Try: Show it: "After pass 1: n = 10, count = 1".
- No final answer line. The AI may not say clearly what gets printed. Try: Add: "Then one line: Prints: <output>."
- Code you don't need. The AI may rewrite the program with print statements inside. Try: Add: "No code."
What a strong prompt includes
- Shows the line shape
- Sets the number of lines
- Asks for the output line
- Rules out explanation
Related exercises
- Add a cron line that matches the others in a crontab (Coding AI · Product managers)
- Add dark mode by overriding your existing CSS variables (Coding AI · Software developers)
- Add input checks to your number guessing game (Coding AI · High school students)
- Add input validation to a Java method with exact messages (Coding AI · Software developers)
- Add labels to a signup form without rewriting the page (Coding AI · High school students)