DOC PREVIEW
UT Arlington CSE 3302 - Control

This preview shows page 1-2-3-4-5-35-36-37-38-39-70-71-72-73-74 out of 74 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 74 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CSE 3302Lecture'13:'Control9'Mar'2010Nate'NystromUniversity'of'Texas'at'ArlingtonMonday, March 22, 2010Gotogoto'L''––'transfer'control'to'the'statement'labeled'Lunrestricte d'control'flow2Monday, March 22, 2010Goto considered harmfulSpagheH'code:int$n$=$0;while$(1)${$$$$if$(n$<=$10)$goto$A;$else$goto$B;$$$$C:$$$$n++;}B:return$n;A:printf(“%d\n”,$n);goto$C;3Monday, March 22, 2010Structured programming1960swhile'loopsdo'loopsfor'loopsifJthenJelsestatement'blocks4Monday, March 22, 2010Break and continueBreak◾leave'the'current'loop,'resume'aNer'the'loopConOnue◾leave'the'current'loop'iteraOon,'resume'at'to p'o f'lo op5Monday, March 22, 2010For loopsPascal:for$x$:=$1$to$10$do$$$$writeln(x)C:for$(x$=$1;$x$<$10;$x++)$$$$printf(“%d\n”,$x);6Monday, March 22, 2010IterationList<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);for$(int$i$=$0;$i$<$counting.size();$i++)${$$$$String$s$=$counting.get(i);$$$$println(s);}7Monday, March 22, 2010Java iteratorsList<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);for$(String$s$:$counting)${$$$$println(s);}8Monday, March 22, 2010Java iteratorsList<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);for$(String$s$:$counting)${$$$$println(s);}shorthand'for:for$(Iterator<String>$i$=$counting.iterator();$i.hasNext();$)${$$$$String$s$=$i.next();$$$$println(s);}9Monday, March 22, 2010Java iteratorsUsing'iterators'is'easy.How'about'wriOng'one?10Monday, March 22, 2010Writing a Java iteratorImplement'java.uOl.Iteratorinterface'Iterator<T>'{''''boolean'hasNext();''''T'next();}11Monday, March 22, 2010Writing a Java iteratorclass$ArrayListIterator<T>${$$$$ArrayList<T>$list;$$$$int$pos$=$0;$$$$boolean$hasNext()${$return$pos$<$list.size();$}$$$$T$next()${$$$$$$$$if$(pos$<$list.size())${$$$$$$$$$$$$pos++;$return$list.get(posR1);$$$$$$$$}$$$$$$$$else$throw$new$NoSuchElementException();$$$$}}12Monday, March 22, 2010Writing a Java iteratorclass$TreeSet<T>${$$$$$TreeNode<T>$root;$$$$$class$TreeNode<T>${$TreeNode<T>$left,$right;$T$value;$}}class$TreeIterator<T>${$$$$TreeSet<T>$tree;$$$$Stack<TreeNode<T>>$stack;$$$$void$pushLeft(TreeNode<T>$n)${$$$$$$$$if$(n$!=$null)$stack.push(n);$pushLeft(n.left);$}$$$${$pushLeft(tree.root);$}$$$$boolean$hasNext()${$return$!$stack.isEmpty();$}$$$$T$next()${$$$$$$$$TreeNode<T>$x$=$stack.pop();$$$$$$$$pushLeft(x.right);$$$$$$$$return$x.value;$$$$}}13Monday, March 22, 2010Writing a Java iteratorIterator'needs'to'maintain'state◾what'have'I'already'returned?◾what'do'I'return'when'next'invoked?14Monday, March 22, 2010Hashtable'iteratorWhat'bucket'am'I'currently'in?Where'in'the'bucket'am'I?15Monday, March 22, 2010A better way16Monday, March 22, 2010Coroutine iteratorsclass$ArrayList<T>${$$$$T[]$array;$$$$Iterator<T>$iterator()${$$$$$$$$for$(int$i$=$0;$i$<$size;$i++)${$$$$$$$$$$$$yield$array[i];$$$$$$$$}$$$$}}for$(T$x$:$list)${$$$$println(x);}17Monday, March 22, 2010class$ArrayList<T>${$$$$T[]$array;$$$$Iterator<T>$iterator()${$$$$$$$$for$(int$i$=$0;$i$<$size;$i++)${$$$$$$$$$$$$yield$array[i];$$$$$$$$}$$$$}}for$(T$x$:$list)${$$$$println(x);}yield'suspends'the'iterator,'returns'control'back'to'the'caller'(for)When'iterator'next'invoked,'resume'aNer'the'previous'yield'18Monday, March 22, 201019for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);$$$$$Monday, March 22, 201020for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$0Monday, March 22, 201021for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$0Monday, March 22, 201022for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$0Monday, March 22, 201023for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$0yanMonday, March 22, 201024for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$0yanMonday, March 22, 201025for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$1yanMonday, March 22, 201026for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$1yanMonday, March 22, 201027for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$1yanMonday, March 22, 201028for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$1yantanMonday, March 22, 201029for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$1yantanMonday, March 22, 201030for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$2yantanMonday, March 22, 201031for$(int$i$=$0;$i$<$size;$i++)${$$$$yield$array[i];}for$(String$s$:$counting)${$$$$println(s);}List<String>$counting$=$$$$Arrays.asList(“yan”,$“tan”,$“tethera”,$“methera”,$“pip”);i$=$2yantanMonday, March 22,


View Full Document

UT Arlington CSE 3302 - Control

Documents in this Course
Smalltalk

Smalltalk

11 pages

Syntax

Syntax

5 pages

Syntax

Syntax

5 pages

JAVA

JAVA

57 pages

Semantics

Semantics

41 pages

Load more
Download Control
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Control and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Control 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?