PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Learn
Examples
C Intro
Basics
Repeat at Least Once.c
1
/*
2
Repeat at Least Once.c
3
4
You can use do...while to make sure a loop executes at least once, even
5
if the condition it uses for repeating is not true. This program shows
6
how it works by displaying n = n + 5 every half second while n <= 10. The
7
loop works normally, but if you change it to while(n <= -10), it still
8
executes the code inside once even though the condition isn't true. So,
9
you will see it display n = 0. Also, by the time it gets to print("All
10
done!"), n will store 5 because the code in the do...loop was executed
11
once.
12
13
http://learn.parallax.com/propeller-c-start-simple
14
*/
15
16
#include "simpletools.h"
// Include simpletools header
17
18
int
main
()
// main function
19
{
20
int
n = 0;
// Declare n, initialize to zero
21
do
// Do the loop ended by while
22
{
23
print(
"n = %d\n"
, n);
// Display name & value of n
24
n = n + 5;
// Add 5 to n each time through
25
pause(500);
// 0.5 s between repetitions
26
}
27
while
(n <= 10);
// Back to do if condition true
28
print(
"All done!"
);
// Display all done
29
}
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12