58
votes
Teaching the humble for loop
Show then how the loop can be unfolded into a while loop:
int i = 0 // Step 1
while (i< 100) { // Step 2
// Do something
i++ // Step 3
}
Explain that ...
34
votes
Accepted
Teaching the humble for loop
I know I'm coming late to this party but this is a really good question and I think it deserves a really good treatment.
The original for loop, the one with the ...
28
votes
Teaching the tradeoffs of the foreach loop
I think the advantages are huge, overwhelming.
They avoid
off by one errors - the bane of the novice programmer
needing to allocate an explicit iterator - avoiding adding names to the namespace.
...
26
votes
Teaching the humble for loop
I teach for loops using the following pseudocode, which we then translate into actual code:
...
17
votes
Order to teach looping constructs in a non ideal language
I prefer to teach while loops as part of my unit on if/else statements since the syntax and ...
10
votes
Teaching the tradeoffs of the foreach loop
I think foreach loops are great, and are almost always preferred over for loops. While for loops are fundamental material and definitely should be covered, they're sort of infrequently used in ...
9
votes
Teaching the tradeoffs of the foreach loop
There is much discussion here about how a traditional for seems more powerful than a foreach, but a traditional ...
9
votes
Teaching the humble for loop
It's about setting boundary conditions first. Provide them with a more concrete example, like filling a glass of milk. You kind of need a glass or container (let me know the next time you pour milk ...
8
votes
Teaching the humble for loop
tl;dr– A for loop is just a while loop that has extra slots for a pre-loop statement and a post-loop-run statement. Since they'...
8
votes
Teaching the humble for loop
Theoretically, I teach the while loop first. Others have already explained how and why, but I'll go ahead with an example:
...
8
votes
Accepted
How to teach which loop should be used
Use the for when you know how many times to execute it, such as counting, or iterating over an array. Use while or ...
8
votes
Order to teach looping constructs in a non ideal language
All of the IF and Loop structures are based on two fundamental operations: Test and Branch. The only difference between an IF-Else and a Loop of any kind is whether you branch downward or back to the ...
7
votes
How to teach which loop should be used
I teach them while loops, for loops, and for each loops; in that order.
What I've found is that while loops tend to make the most sense for students. The idea of while I'm hungry, eat pizza is ...
7
votes
Teaching the humble for loop
I think the way to teach it is not by talking about order of operation, but by teaching the overall concept of a looping. The for header contains the steps that are ...
7
votes
Single-dimensional array and simple looping activities of significance
The Dutch National Flag problem is linear in running time. Essentially sort an array with only 3 distinct values each of which may appear 0 or more times. (not length 3). You are allowed only one pass ...
7
votes
Single-dimensional array and simple looping activities of significance
A variant on the ENIGMA machine encryption works well in a single loop, and is sufficiently complex to give students a real challenge.
The core idea of the ENIGMA machine for this assignment is that (...
6
votes
Example for For vs While Loop (in Java)
If I'm interpreting your question correctly you'd like real life examples that translate to code. Maybe something like the following.
You want to drive or ride your bike to the ice-cream shop a few ...
6
votes
Teaching the humble for loop
I used to have a role where I supported college students in CS1. I developed the following exercises to address this exact issue:
Counting code executions
Text version:
How many times do each of the ...
6
votes
Using physical activity to explain the nested for loop
Your pupils are already be doing nested loops.
...
5
votes
How to teach which loop should be used
I find that a useful way of teaching the different types of loops is simply giving examples and asking student to express them more concisely. For example, I'd give my students a loops of the format:
...
5
votes
Accepted
Order to teach looping constructs in a non ideal language
While your ideal order makes sense, you really should try to plan the course based on the limitations of the language that you're working with. In this case, instead of thinking about the different ...
4
votes
Teaching the humble for loop
Maybe the
for (int i=0; i<10; i++)
{ ... }
loops seems funny when you compare it to the "interval" loop of other languages, like Pascal's
...
4
votes
Teaching the tradeoffs of the foreach loop
To do something like the following with foreach...
...
4
votes
How to teach which loop should be used
I introduce loops by showing them loops in the physical world. For example I have a student take 7 steps - counting loop. An other student walks to a specified point - while/until loop. We talk about ...
4
votes
Teaching the humble for loop
I am not an educator, but I hope my answer will be helpful.
In B.A.S.I.C, which I learned as a child, there are "for-to-step" loops and their argument order is the same as C style languages. I have ...
4
votes
Using physical activity to explain the nested for loop
Well, you may want to do this outside. You may want to have a lot of time, and for some, you might want to have medical personnel available.
To really do it as an active learning exercise, you need ...
4
votes
Order to teach looping constructs in a non ideal language
Perhaps you are creating a problem where none exists. You seem to be assuming that looping needs to be covered all at once and all together, rather than distributed over some some longer range ...
4
votes
What are good, practical labs and activities for loops?
Note that the following are intended for the instructor, not always directly for the student. If used well they require some analysis, not just coding, from the student.
Use the fact that the sum of ...
4
votes
What are good, practical labs and activities for loops?
I'm adding in a second answer to look at a few heftier assignments, worthy of a lab. These were created by a truly fantastic colleague of mine.
The game Nim is excellent for a loop with no arrays. ...
3
votes
Teaching the humble for loop
Another way of looking at this is to explore what is missing or lost at various stages:
In Java
For each:
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
looping × 10lesson-ideas × 2
java × 2
algorithms × 2
best-practice × 1
programming × 1
introductory-lesson × 1
labs × 1
active-learning × 1
cs-theory × 1
code-example × 1
arrays × 1
lesson-order × 1
secondary-education × 1
imperative-programming × 1