Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 115:8bd6e72f6e28
- Parent:
- 114:1cfad1babb55
--- a/main.cpp Tue Oct 12 21:48:12 2021 +0000 +++ b/main.cpp Wed Oct 13 15:51:01 2021 +0000 @@ -1,5 +1,5 @@ /* -Project: 21_ScopeEx1_v5 +Project: 21_ScopeEx2_v5 File: main.cpp This simple program demonstrates that C passes arguments by value. @@ -18,17 +18,14 @@ const char ESC = 27; // Define escape character for escape sequence. printf("%c[2J%c[H", ESC, ESC); // ANSI/VT100 clear screen/home. - int count1 = 1; // Declared in outer block + int count = 0; // Declared in outer block. + do { + int count = 0; // This is another variable called count. + ++count; // this applies to inner count. + printf("count = %d\n", count); + } while( ++count <= 5); // This works with outer count. - do { // Do while construct may be new to you! - int count2 = 0; // Declared & initialized in inner block - ++count2; // Ineffective due to line above! - printf("count1 = %d count2 = %d\n", count1, count2); - // Note that count1 is incremented in while test! - } while (++count1 <= 5); // count2 no longer exists after loop exit. - - printf("count1 = %d\n", count1); - return 0; + printf("count = %d\n", count); // Inner count is dead. while(true) { // Main forever loop. ThisThread::sleep_for(DELAY); // Pause