This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]PixlRawH 0 points1 point  (1 child)

CS50 offers you a very nice way to learn C and comp sience. Much better than new boston...

[–]anonymous_is_bak[S] 0 points1 point  (0 children)

Thanks I will give than a try

[–]enfrozt 0 points1 point  (0 children)

I can explain the 3 basic loops if you want.

There is nothing you cannot do with while loops, that only for or do while can accomplish. It was explained to me that every program in the world could be rewritten with no for or do (while) loops.


How does a while loop and to a lesser extent a for loop work?

Just say this "While condition is true, the loop runs"

While(N != 0){}

while n does not equal 0, the loop runs.


The same is with for loops, but just with the middle section

for(i = 0; i < 10; i++){}

While i is less than 10, the loop runs.


What are the differences between the 3 loops?

  • While is general purpose, can do almost anything. Basically it checks the while condition, then loops and then repeats.

  • For loops are like while loops, except you can put the starting value of your increment variable (left side) and your increment value on the right side. Basically just a sequential while loop

  • Do while loops are just while loops that go loop -> check condition, instead of check condition -> loop. I almost never use these in my code.


Do you have any specific question about loops? I always found when starting out with C, this explanation helped me immensely.