cs246-s11-001-may24

cs246-s11-001-may24 - CS 246 (Spring 2011) Section 1...

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

View Full Document Right Arrow Icon
CS 246 (Spring 2011) – Section 1 Tuesday 24 May Structured Programming (continued), Enumeration, and Pointers
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Tuesday 24 May 2 Today's Agenda 2.6.2 Multi-level exit Continued from last week 2.7.1 Enumeration 2.7.2 Pointer/Reference Will continue this next class
Background image of page 2
CS 246 (Spring 2011) - Section 001 - Tuesday 24 May 3 2.6.2 Multi-level Exit Multi-level exit : exit multiple control structures where exit points are known at compile-time We would like to have a labelled break/continue as in Java (see below) But C++ does not allow this feature L1 : for ( . . . ) { L2 : while ( . . . ) { if ( . . . ) break L1 ; if ( . . . ) break L2 ; } }
Background image of page 3

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Tuesday 24 May 4 Label variables Labels are declared and associated with a statement Declare in a routine using colon, has routine scope Differs from other local variables : each label is unique within a routine body int L1; // not a label L2 : ; // label on empty statement if ( true ) { double L1; // allowed double L2 ; // not allowed }
Background image of page 4
CS 246 (Spring 2011) - Section 001 - Tuesday 24 May 5 Goto statements Allows arbitrary transfer of control to a labelled statement within a routine goto L1; L0 : ; // label on empty statement? cout << “must be positive” << endl; L1 : ; int x = get_number(); if (x < 0) goto L0 ; else if (x == 3) goto L2 ; else goto L1 ; L2 : ; cout << “correct” << endl;
Background image of page 5

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

View Full DocumentRight Arrow Icon
CS 246 (Spring 2011) - Section 001 - Tuesday 24 May 6 Simulating labelled break Rewrite the Java syntax of a labelled break (below) using goto statements Multi-level exits common with nested loops A multi-exit loop is the simplest case of a multi-level
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 12/08/2011 for the course CS 246 taught by Professor Wormer during the Spring '08 term at Waterloo.

Page1 / 19

cs246-s11-001-may24 - CS 246 (Spring 2011) Section 1...

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