For Loop, While Loop, IF loop

For Loop, While Loop, IF loop
What is the difference?
The help file wasn’t specific

Thanks

a for loop is basically this for(int x = o; x<10; x++) the first part(in bold) is what happens when the for loop first starts. Then the second part(in italics) determines how long the for loop will run for. The last part(underlined) is what happens every time the loop is succesfully completed. So what happens is it will first create x and set it to 0, then as long as x < 10 it will keep executing the code inside the loop, After every execution x is increased by one.

An if loop is a lot simpler. for example if(x<10) The part in bold determines whether or not the loop will execute. if x is less than 10 it will execute the code inside the loop(although its not really a loop it only gets executed once). if x is not less than 10 then the loop won’t execute. if statements are sometimes accompanied by else statements which are if the the if statement does not run then the else statement will. If else…

a while loop is similar to a for loop. For example while(x<10) do this(whatever this is) with while statements you change the value of x in this case inside the loop, there are man different ways x can change. Although while and for statements are similar they both have separate applications.

Hope this helps.

I’m sorry that I don’t remember the specifics about the C syntax involved in this topic; but one significant difference between For and While loops in some languages is whether or not the loop is guaranteed to execute at least once.

This difference arise because of the time at which the loops conditional test are executed.

In loops where the test is done at the top of the the loop, if the test fails the loop will be almost-certainly bypassed (I can’t think of a language I have studied in which this wasn’t the case, but you never know what might be out there in some exotic language…).

In loops where the test is performed at the bottom of the loop, the language syntax loop will almost-certainly execute one pass through the loop’s instructions, then perform the test, and then fall out of the loop.

You can easily test EasyC’s behavior empirically with a little code and some print statements. Or you can look up a reference for C syntax. Ther must be zillions of them available online in various forms.

Blake
PS, if you explicitly use If statements to form a loop, then you will know exactly shere you place your test that determines whether to execute a pass through the loop. However your code will be a bit uglier and harder to read or understand.

Thanks for the help!

I am going to point you to my page I have for ‘C’ Resources. The following links are found there.

Start with these Links from Programming in C for discussions on IF, FOR, WHILE (and DO-WHILE).

If you have the Bandwidth, download the Thinking in ‘C’ tutorial, (Warning, 95 Megabytes !!! ).