mike
Posts: 4
Nickname: mikez
Registered: Jul, 2003
|
|
Re: Whats a 'unreachable statement'?
|
Posted: Jul 19, 2003 1:32 PM
|
|
> I am making a Treemap in which the user is prompted for a > word and then a definition. These are stored in the > Treemap. Later the user is prompted to enter a word, and > the treemap goes in to look for the word. If found, the > definition of the word is returned. Here is what i have so > far: > > > import java.util.*;
>
> public class MapTree
> {
> public static void main(String[] args)
> {
> Terminal t = new Terminal();
>
> TreeMap theMap;
> theMap = new TreeMap();
>
> String b;
> String c;
> while (true)
> {
> b = t.readLine("Enter key: ");
> c = t.readLine("Enter value: ");
> theMap.put("b", new String(c));
> }
>
> Iterator iter = theMap.keySet().iterator();
> r(); //@@@@@@//
>
> while (iter.hasNext()) {
> b = (String) iter.next();
> c = (String) theMap.get(b);
> // do something with key and value.
>
> }
>
>
>
>
>
> }
> }
>
> > My problem lies at the line: Iterator iter = > theMap.keySet().iterator(); > > When i try to compile, i get: $ javac MapTree.java > MapTree.java:22: unreachable statement > Iterator iter = theMap.keySet().iterator(); > ^ > 1 error > > > How do i fix that? > > Thanks.
you will never reach the statement after the while loop because while(true) is an infinite loop. ie. the while loop will continue on forever and never reach anything after the while loop.
|
|