L05 - top down design - modules

L05 - top down design - modules - Today Finish looking...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ review & C++/CLI - Basics Today, -- – Finish looking at/reviewing the looping structures in C++ – Explore the issue of output in C++/CLI – a little more – Proceed with an example that uses a switch construct embedded in a loop along with use of some character types that we haven’t yet seen in C++/CLI – move on to look at rules for generating programs that are well structured – continue our discussion of standard C++ and C++/CLI, moving on to functions and beyond • in doing this, we’ll consider what value and reference types are, what the duration of a thing is and what its scope is
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ review & C++/CLI - Basics For-Loops (cont) for (int x = 1; x <= 50; x++) keyword control variable declaration final “acceptable” control variable value initial value of the control variable loop continuation condition control variable increment expr2 expr1 loop body expr3 F T A for loop can be realized using a while: exp1; while (exp2){ statements; exp3; }
Background image of page 2
C++ review & C++/CLI - Basics For-loops – some observations: • In standard C++: – If exp1 declares a variable, then that variable can only be used within the for structure • exp1 and exp3 may have more than one component statement: for (x=0, y=0; x < limit; x++, y--) int main(array<System::String ^> ^args) { int i = -10; for (int i=1; i<10; i++) {Console::Write (L"i = {0} \t", i.ToString());} Console::WriteLine(L"\n i after the loop is {0}", i.ToString()); Console::ReadLine(); return 0; }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ review & C++/CLI - Basics Break and Continue • The break statement can be used in while , do/while , for , and switch structures – Execution of a break statement causes an immediate exit from the structure • The continue statement can be used in while , do/while , and for structures – Execution of a continue statement causes the remaining statements in a loop to be skipped and the next iteration of the loop to begin • In while and do/while structures, the loop condition is tested immediately • In the for structure, the control variable(s) increment statements are executed immediately and the loop condition tested right after that
Background image of page 4
C++ review & C++/CLI - Basics for each looping structures • New to you – it wasn’t part of the standard C++ control structures you saw last semester • Syntax: for each (type identifier in expression) { statements } Example: int main() { String ^ MyString = gcnew String("abcd"); for each ( Char c in MyString ) Console::Write(c); Console::WriteLine(); } type of the identifier iteration variable managed array expression or collection
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
C++ review & C++/CLI - Basics Using for each to do a “real” task void vowels() { int vowels = 0; int consonants = 0; String^ proverb = L"It's always good to beat SLU."; for each(wchar_t ch in proverb) { if(Char::IsLetter(ch)) { ch = Char::ToLower(ch); // Convert to lowercase switch(ch) { case 'a': case 'e': case 'i': case 'o': case 'u':
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/08/2008 for the course EE 361 taught by Professor Conry during the Spring '08 term at Clarkson University .

Page1 / 20

L05 - top down design - modules - Today Finish looking...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online