课程: Java Essential Training: Syntax and Structure
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Break statement
- [Angie] Sometimes you may need to get out of a loop regardless of what the condition is. We can use the break statement for this. We're going to create a program that searches a string to determine if it contains the letter A. So far, I have prompted the user to enter text and have stored that text within the string. Now, we're going to use a For Loop to search the text. So we'll say for, and we'll initialize I as zero, and our condition should indicate to loop until we've reached the end of the string. So we'll say I is less than, and strings have a convenience method called length, which will return the number of characters in the string. And then finally, we'll say i++ to increment the loop. Inside of the loop, let's go ahead and store the letter we're currently working on in a variable. And we'll call this currentLetter, and we'll say text.charAt, and specify the index, which will be I. So this will give us the…
随堂练习,边学边练
下载课堂讲义。学练结合,紧跟进度,轻松巩固知识。