Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!alberta!mts.ucs.UAlberta.CA!Al_Dunbar From: userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) Newsgroups: comp.lang.c Subject: Re: Comparing strings... Message-ID: <1717@mts.ucs.UAlberta.CA> Date: 18 Oct 90 04:27:05 GMT References: <2205.271700c2@cc.nu.oz.au> <1990Oct13.190106.15615@ux1.cso.uiuc.edu> <10678.271ade27@amherst.bitnet> Organization: MTS Univ of Alberta Lines: 28 In article <10678.271ade27@amherst.bitnet>, twpierce@amherst.bitnet (Tim Pierce) writes: >In article <1990Oct13.190106.15615@ux1.cso.uiuc.edu>, >gordon@osiris.cso.uiuc.edu (John Gordon) writes: > <<>> >> for(i = 0; s1[i] && s2[i]; i++) >> { >> if(s1[i] > s2[i]) >> return(S1_BIGGER); >> else if(s1[i] < s2[i]) >> return(S2_BIGGER) >> } > >Correct me if I'm wrong here (being a C neophyte myself), but shouldn't you be >using a while loop rather than a for loop? It looks to me as if this code will >return only the relative sizes of the last characters in the string, not >stopping once an inequality is hit. Or does the return() statement imply a >break? > The return() statement (or just "return;") "implies a break" in the same way that going outside implies that you have left the room. -------------------+------------------------------------------- Al Dunbar | Edmonton, Alberta | this space for rent CANADA | -------------------+------------------------------------------- #! r