Skip to content

Lab 5 Questions (2 to 4)

Glenn Lopez edited this page Feb 13, 2016 · 3 revisions

Question 3

Describe on paper, the difference between: an “if” statement, a “while” loop, a “do..while” loop, and a “for” loop. Put this assignment in your Lab Manual (your duotang folder) along with the rest of Lab 5. This will be part of your mark.

If statement:
Checks whether the text expression inside parenthesis ( ) is true or not. if (test expression) { statement/s to be executed if test expression is true; }

While loop:
The while loop checks whether the test expression is true or not. Stops executing when expression is false. while (test expression) { statement/s to be executed. }

Do..While:
Code is executed at first then the condition is checked. So, the code are executed at least once in do...while loops in the beginning EVEN IF the test condition is false (since it doesnt test the condition till after the code has executed). do { some code/s; } while (test expression);

For loop:
The initialization statement is executed only once at the beginning of the for loop. Then the test expression is checked by the program. If the test expression is false, for loop is terminated. for(initialization statement; test expression; update statement) { code/s to be executed; }

Useful for iterating a loop when you have an idea for how long you need something to loop.

The first program, 5.1 (lab5_1.c) is used to test your hardware and wiring. Study how it works and try it out. Troubleshoot any hardware connection errors. Next, study the requirements for program assignment 5.3. Then, draw a flowchart that describes how programming assignment 5.3 is supposed to work.

in progress...

Write program 5.3 (lab5_3.c) based on your flowchart. Put this lab, along with your flowchart, in your Lab Manual. Demonstrate your running program to your instructor.

in progress...

Clone this wiki locally