PropWare
3.0.0.229
C++ objects and CMake build system for Parallax Propeller
Simple-Libraries
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
}
pause
void pause(int time)
Delay cog from moving on to the next statement for a certain length of time.
Definition:
libws2812.c:125
simpletools.h
This library provides convenient functions for a variety of microcontroller I/O, timing,...
print
int print(const char *format,...) __attribute__((format(printf
Print format "..." args to the default simple terminal device. The output is limited to 256 bytes.
main
int main(void)
Definition:
GraphicsTest.c:20
Generated on Fri May 20 2022 16:48:04 for PropWare by
1.8.17