-
Notifications
You must be signed in to change notification settings - Fork 4
Lab 5 Questions (2 to 4)
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...
If you are having trouble with this course, I highly suggest you learn how to program in C using code::blocks before doing anything with your microcontroller. This course is poorly designed and failing at it may not be entirely your fault. How well you do in your courses is a reflection of how good your instructors are -- never give them an excuse to say otherwise. “The mind is not a vessel to be filled, but a fire to be kindled.” — Plutarch