Timeline for What are the differences between a while loop and a for loop?
Current License: CC BY-SA 3.0
16 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 10, 2019 at 14:46 | review | Suggested edits | |||
| May 10, 2019 at 16:10 | |||||
| Aug 10, 2015 at 16:38 | history | protected | CommunityBot | ||
| Aug 10, 2015 at 16:38 | comment | added | Basile Starynkevitch |
@JörgWMittag: if the language admit a for loop as general as in C, then it trivially has a while loop....
|
|
| Jun 10, 2014 at 20:00 | comment | added | user53141 |
@JörgWMittag I was unclear...as I said, a for loop is a subset of a while loop.
|
|
| Jun 10, 2014 at 14:57 | comment | added | CodesInChaos |
Which languages are you talking about? C style? In pascal for loops are quite different from C for loops and in some other languages for also allows you to write for each loops.
|
|
| Jun 10, 2014 at 10:57 | comment | added | Vatine |
@JörgWMittag Well, that depends on the for loop, now, doesn't it. Although one could argue that a C for loop is actually a while loop in fancy clothing.
|
|
| Jun 10, 2014 at 9:45 | answer | added | Jörg W Mittag | timeline score: 0 | |
| Jun 10, 2014 at 9:35 | comment | added | Jörg W Mittag | @StevenBurnap: they are not basically the same. A language with only while loops and conditionals is Turing-complete, a language with only for loops isn't. A language with while loops can compute any µ-recursive function, a language with for loops can only compute primitive-recursive functions. A language with for loops can only express programs that always terminate, it cannot express non-termination. | |
| Jun 10, 2014 at 2:15 | comment | added | glampert | Up-voted! No question is too silly when you are learning. | |
| Jun 9, 2014 at 16:48 | comment | added | user53141 |
They are basically the same. A for loop is just syntax sugar, supporting a subset of use cases that while supports. Sometimes "syntax sugar" is looked down upon, but it should really be looked at as a way to create cleaner, easier to understand code.
|
|
| Jun 9, 2014 at 16:47 | vote | accept | mistichor | ||
| Jun 9, 2014 at 9:43 | review | Low quality posts | |||
| Jun 9, 2014 at 11:05 | |||||
| Jun 9, 2014 at 9:39 | history | edited | yannis | CC BY-SA 3.0 |
deleted 78 characters in body; edited tags
|
| Jun 9, 2014 at 7:54 | answer | added | npinti | timeline score: 11 | |
| Jun 9, 2014 at 7:53 | comment | added | try-catch-finally | Try to use both for multiple "challenges". You'll quickly see that one loop construct is better suited for some situation than other loop constructs. And actually there are two types of while loops in some languages (as in Javascript) with their own (special) use cases. In fact both / all three can be used to accomplish a goal, but only one might do the job without too much semantical "overhead" (making it easier to understand e.g.). | |
| Jun 9, 2014 at 7:43 | history | asked | mistichor | CC BY-SA 3.0 |